Script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
rajsdwh
Posts: 1
Joined: 16 Aug 2011 09:26

Script

#1 Post by rajsdwh » 16 Aug 2011 09:32

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.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Script

#2 Post by aGerman » 17 Aug 2011 13:38

What is your output of

Code: Select all

echo %date%

:?:

Regards
aGerman

ptronius
Posts: 1
Joined: 18 Aug 2011 12:41

Re: Script

#3 Post by ptronius » 18 Aug 2011 13:17

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.

Post Reply