1

我的结构中有一堆文件夹(和子文件夹)......

Test/Student001/ABC,
Test/Student001/DEF,
Test/Student002/ABC,
Test/Student002/DEF, etc...

然后我需要做的是将这些文件夹(及其子文件夹和其中的文件)重新定位到另一个位置,这样它就像......

Test/Class01/ArronAmos(Student001)/ABC
Test/Class01/ArronAmos(Student001)/DEF
Test/Class02/BrettBesty(Student002)/ABC
Test/Class02/BrettBesty(Student002)/DEF

我有所有文件夹(和子文件夹)原始名称和新名称的文本文件(像这样保存)..

studentdata.txt

A (studentcode), B (studentnewname), C (Class)

Student001, ArronAmos (Student001), Class01

Student002, BrettBesty (Student002), Class02

有没有办法让一批基本上像这样进行(使用上面文本文件中的 A、B 和 C - 如果可能的话,最好是一个 txt 文件)......

md 'C' ::which will skip past if folder exists

rename folder 'A' to 'B' ::only rename of root folder and leave subfolders intact

move folder 'B' to 'C' ::move new named folder (B) and all subfolders and contents to new root folder (C)

新目录和子文件夹的创建(对于新的和未来的学生)就像这样并且效果很好(除非有一种方法可以调用第二个文本文件来创建子文件夹而不是编码,那会很棒 - 但没什么大不了的我猜)...

创作批次

 cd /d %~dp0 pause

FOR /F "delims=~" %%f in (dirlist.txt) DO md "%%f"

:: This code creates directories referenced from a .txt file: - :: FOR /F "delims=~" %%f in (dirlist.txt) DO MD "%%f"

pause

FOR /D %%x in (*) do mkdir "%%x\Individual Behaviour Plans" "%%x\Individual Learning Plans" "%%x\Student Reports" "%%x\Student Support Group Meetings"

:: This code creates a new dir within every folder in batch location: - :: FOR /D %%x in (*) do mkdir "%%x\value"

pause

这是我从其他技术之一收到的重命名批次,不太了解它或不知道修改它以使其工作..

*rename_users.bat** :: Script to Rename folders - prefixing from a text file

setlocal ENABLEDELAYEDEXPANSION

Set Rootfolder=Test Set Names=names.txt

:: Goto Root Folder cd /d %~dp0

:: Start Line Counter Set LineCount=0

           :: For Every folder in the directory
           For /d /r %%g in (*) DO (
                           :: Increment the line counter by 1 (see the use of "!" >instead of "%" due to delayed expansion)
                           Set /a LineCount=!Linecount!+1
                           :: Call the Rename Folder sub - passing through the >variables of folder name and line counter
                           Call:RenameFolder %%g !LineCount!)
:RenameFolder :: For all of the tokens in the findstr on the names file for /f "Tokens=1* delims=:" %%a in ('findstr /n "^" "%Names%"') DO ( :: If the line counter matches the line number If %%a==%~2 ( :: Rename the Folder Move "%~1" "%~1 %%b") ) ::Return to the Primary 
Goto:EOF

Set Rootfolder= Set Names= Set linecount= Set Drive=

Endlocal

诀窍是我们不能只使用创建目录(和子目录)批处理文件,因为有些文件夹以原始格式存在,其中包含我们需要坐在新结构子文件夹中的数据......并手动移动它们将是一个选择...如果没有 900 多个学生文件夹也可以这样做...

我希望有某种形式的意义......谢谢大家!

4

1 回答 1

0

下面的批处理文件做你想做的事:

@echo off
setlocal EnableDelayedExpansion

rem Enter into working directory
cd C:/Test

rem Process the file with original and new names
for /F "skip=1 tokens=1-3 delims=," %%a in (studentData.txt) do (

   rem Get studentNewName end eliminate spaces
   set "studentNewName=%%b"
   set "studentNewName=!studentNewName: =!"

   rem If the new folder not exist, create it
   if not exist "%%c/!studentNewName!" md "%%c/!studentNewName!"

   rem Move files from old folder 
   move "%%a/*.*" "%%c/!studentNewName!"

   rem And delete old empty folder
   rd "%%a"

)

安东尼奥

于 2013-02-12T16:43:05.230 回答