2013-02-12 70 views
1

我有一大堆的文件夾(和子文件夾)中的結構的文件夾和子文件夾...批量創建文件夾,然後重新定位exisiting使用文本文件

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+的學生文件夾也可以這樣做...

我希望讓某種形式的感覺......謝謝你們!

回答

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" 

) 

安東尼

+0

安東尼奧,我已經測試此批,似乎一半的工作......它可以創建文件夾和子文件夾(如此%% a,%% b和%% c似乎正在工作),但不工作的部分是行...移動「%% a /*.*」「%% c /!studentNewName!」因爲沒有數據移動,然後它會嘗試執行...... rd「%% a」,但它純粹是由於目錄不是空的而失敗......任何想法? – KadeOK 2013-02-13 04:19:56

+0

我玩過它,我可以通過在move和md命令中將'/'的方向切換到'\'來實現它... – KadeOK 2013-02-13 04:30:36

+0

我也剛剛意識到move命令只會將文件移動到文件夾,有沒有辦法讓它移動子文件夾以及我認爲會更多的是一個xcopy函數?我會玩一玩,看看我能做些什麼..感謝您的幫助! :) – KadeOK 2013-02-13 04:42:26

相關問題