Discussion Locked

How to append datetime in dos

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
Can anyone remember how to append a datetimestamp to a file name in dos.

8 replies

by nettek

copy filename.ext /b+ /y

will change the files date and time stamp to the current date and time. If you want to use a specific date and time other than the current settings, you will have to change the system date and time to what you desire before issuing the command.

by joseph moore

Wait, do you want the filename of the file to be something like: FILENAME_AUG_28_2002.TXT
Well, one fast way is like this:

for /f "tokens=1-4 delims=/ " %%i in ('date /t') do rename FILENAME.TXT FILENAME_%%j_%%k_%%l.TXT

Run that line in a BAT file and it will rename a file you specify (replace the FILENAME.TXT with your file's name) to be FILENAME_08_28_2002.TXT

If you want to run this FOR line at the command prompt itself (NOT in a BAT file), then just change the %% variable namesto using a single % sign. YOu use double %% symbols in BAT files, not at the command line itself.

hope this helps

by sgt_shultz

I got this to work by looking up the rename command in this book, "Windows NT Shell Scripting" by Tim Hill page 324: "you cannot specify a new drive or directory for the new file name - rename cannot move files" eg.rename wants the 'source' filenameto have a path but for the new file name only the filename, e.g.
rename c:\filename.txt newfilename.txt.
Thanks bunches, Joesph. need to cobble up a poorman's modified backup system using robocopy. big help. thanks

This discussion is closed to new replies.