I have a requirement where I need to copy and rename files from a one location to another:
Fox example: The File name is Report MOR.pdf. This file has to be copied to another location and renamed to Report MOR - MON - YYYY (Report MOR - AUG - 2011). Please share your thoughts in writing this script.
Script
Moderator: DosItHelp
Re: Script
How about this:
FOR /F "TOKENS=1-4 DELIMS=/ " %%i IN ('DATE /T') DO SET DT="-"%%j"-"%%l
XCOPY C:\FOLDER1\MOR.TXT C:\FOLDER2\MOR%DT%.TXT
Unfortunately I do not know how to suppress the message that comes up asking if the resultant filename is a file or a directory.
You might want to consider using the date as a directory name instead of part of the filename. Using the same concept as above but slightly changed...
FOR /F "TOKENS=1-4 DELIMS=/ " %%i IN ('DATE /T') DO SET DT=%%j"-"%%l
XCOPY C:\FOLDER\MOR.TXT C:\FOLDER\%DT%\*.*
This avoids the message concerning whether the result is a file or a directory.
FOR /F "TOKENS=1-4 DELIMS=/ " %%i IN ('DATE /T') DO SET DT="-"%%j"-"%%l
XCOPY C:\FOLDER1\MOR.TXT C:\FOLDER2\MOR%DT%.TXT
Unfortunately I do not know how to suppress the message that comes up asking if the resultant filename is a file or a directory.
You might want to consider using the date as a directory name instead of part of the filename. Using the same concept as above but slightly changed...
FOR /F "TOKENS=1-4 DELIMS=/ " %%i IN ('DATE /T') DO SET DT=%%j"-"%%l
XCOPY C:\FOLDER\MOR.TXT C:\FOLDER\%DT%\*.*
This avoids the message concerning whether the result is a file or a directory.