Copy a file and appending a timestamp to its name...

I need to know if I can append the timestamp to the end of the filename using the command line in Windows XP. I have a couple of jobs in Unix, where I can do this, and I need help doing this in Windows.

Example:

I have a file:                CCAOPCL.txt (it always has this name)

I want to copy that file to:
                                  CCAOPCL_20060523.txt

SharonBernalAsked:
Who is Participating?
 
LeeTutorretiredCommented:
Here's a web page that describes a batch file to do very close to what you want:

http://www.windowsitpro.com/Article/ArticleID/13575/13575.html

You would need to change the "rename" command to "copy" in the batch file, and if you're not interested in the time being appended to the file name, but only the date, then just leave out references to that.
0
 
Dragon_KromeCommented:
I don't think you can do that by using only the commandline. You could try to create a script though, and run it via WSH

Here's an example script which gets the date/time of a file, among others.
http://www.winscripter.com/WSH/FileIO/68.aspx

For copying the file, you can do something like fso.CopyFile(src,dest,true);  (see this other script which performs copying: http://www.winscripter.com/WSH/FileIO/290.aspx)

0
 
FriarTukCommented:
here's my own personal batch,

::: will set zdate to YYYYMMDD
SET zdate=%date:~-4%%date:~4,2%%date:~7,2%
::: will add date to end of file name
COPY c:\CCAOPCL.txt c:\CCAOPCL_%zdate%.txt

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.