Page 1 of 1

Script

Posted: 16 Aug 2011 09:32
by rajsdwh
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.

Re: Script

Posted: 17 Aug 2011 13:38
by aGerman
What is your output of

Code: Select all

echo %date%

:?:

Regards
aGerman

Re: Script

Posted: 18 Aug 2011 13:17
by ptronius
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.