Batch moving using text file
Posted: 09 Mar 2011 06:11
Hi,
I have around 2000 pdf files that each must go to a different folder. I made a list of them containing old file names, & new file path & names (like : --\--.pdf) the path is in 3 levels. can I move & rename files using this list? I don't have any scriping knowledge
All of my files are under 4 sub directories under directory named "Auditing Reports"
example of my List.txt:
I created the list using excel so there is no relation between old & new file names.
Thanks In Advance
Edit: Answer provided by !k:
pattern of list.txt:
Code in batch file:
Notes:
I have around 2000 pdf files that each must go to a different folder. I made a list of them containing old file names, & new file path & names (like : --\--.pdf) the path is in 3 levels. can I move & rename files using this list? I don't have any scriping knowledge
All of my files are under 4 sub directories under directory named "Auditing Reports"
example of my List.txt:
Code: Select all
OldName|NewPath
001S.pdf|D:\Auditing Reports\A\B\S-88.pdf
002S.pdf|D:\Auditing Reports\C\D\S-87.pdf
I created the list using excel so there is no relation between old & new file names.
Thanks In Advance
Edit: Answer provided by !k:
pattern of list.txt:
Code: Select all
file name|source directory\|destination directory
Code in batch file:
Code: Select all
for /f "tokens=1,2,3 delims=|" %%f in (List.txt) do (
if "%%~xh"=="" (md "%%h" 2>nul) else md "%%~dph" 2>nul
move "%%g%%f" "%%h"
)
Notes:
- if you dont have source directory:
pattern of list.txtCode: Select all
file name|destination directory
Code in batch file:Code: Select all
for /f "tokens=1,2 delims=|" %%f in (List.txt) do (
if "%%~xg"=="" (md "%%h" 2>nul) else md "%%~dpg" 2>nul
move "%%f" "%%g"
)
OR you can simply put two quotes ("") replacing "source directory\" above - destination directory can be a path with new file name