Thursday, 15 April 2010

Batch create folders then relocate exisiting folders and subfolders using text file -



Batch create folders then relocate exisiting folders and subfolders using text file -

i have bunch of folders (and subfolders) in construction of...

test/student001/abc, test/student001/def, test/student002/abc, test/student002/def, etc...

what need relocate folders (and subfolders , files within) location like...

test/class01/arronamos(student001)/abc test/class01/arronamos(student001)/def test/class02/brettbesty(student002)/abc test/class02/brettbesty(student002)/def

i have text files folders (and subfolders) original , new names (saved so)..

studentdata.txt (studentcode), b (studentnewname), c (class) student001, arronamos (student001), class01 student002, brettbesty (student002), class02

is there way batch go (using a,b , c text file above - preferably 1 txt file if possible)...

md 'c' ::which skip past if folder exists rename folder 'a' 'b' ::only rename of root folder , leave subfolders intact move folder 'b' 'c' ::move new named folder (b) , subfolders , contents new root folder (c)

the creation of new directories , subfolders (for new , future students) goes , works great (except if there way phone call 2nd text file subfolder creation rather coded in awesome - no biggy guess)...

the creation batch

cd /d %~dp0 pause /f "delims=~" %%f in (dirlist.txt) md "%%f" :: code creates directories referenced .txt file: - :: /f "delims=~" %%f in (dirlist.txt) md "%%f" pause /d %%x in (*) mkdir "%%x\individual behaviour plans" "%%x\individual learning plans" "%%x\student reports" "%%x\student back upwards grouping meetings" :: code creates new dir within every folder in batch location: - :: /d %%x in (*) mkdir "%%x\value" pause

and rename batch received off 1 of other techs , don't quite understand or know modify create work..

*rename_users.bat** :: script rename folders - prefixing text file setlocal enabledelayedexpansion set rootfolder=test set names=names.txt :: goto root folder cd /d %~dp0 :: start line counter set linecount=0 :: every folder in directory /d /r %%g in (*) ( :: increment line counter 1 (see utilize of "!" >instead of "%" due delayed expansion) set /a linecount=!linecount!+1 :: phone call rename folder sub - passing through >variables of folder name , line counter call:renamefolder %%g !linecount!) :renamefolder :: of tokens in findstr on names file /f "tokens=1* delims=:" %%a in ('findstr /n "^" "%names%"') ( :: if line counter matches line number if %%a==%~2 ( :: rename folder move "%~1" "%~1 %%b") ) ::return primary goto:eof set rootfolder= set names= set linecount= set drive= endlocal

the trick can't utilize create directories (and subdirectories) batch file, there folders existing in original format have info in them need sitting in new structures subfolders... , moving them manually option... if there not 900+ pupil folders too...

i hope makes form of sense... guys!

the batch file below want:

@echo off setlocal enabledelayedexpansion rem come in working directory cd c:/test rem process file original , new names /f "skip=1 tokens=1-3 delims=," %%a in (studentdata.txt) ( rem studentnewname end eliminate spaces set "studentnewname=%%b" set "studentnewname=!studentnewname: =!" rem if new folder not exist, create if not exist "%%c/!studentnewname!" md "%%c/!studentnewname!" rem move files old folder move "%%a/*.*" "%%c/!studentnewname!" rem , delete old empty folder rd "%%a" )

antonio

batch-file

No comments:

Post a Comment