Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file to copy text-file and include date in name 1

Status
Not open for further replies.

StuartJones

Programmer
Jul 10, 2002
30
GB
I need to write a batch file which will copy a text-file on a daily basis.

It will then rename the copy to include the date on which this action was carried out.

Could someone tell me the commands for this, please?

Thanks in advance, Stuart
 
Slap this in a batch file should do the trick. Call it passing in 2 parameters.
1) The path/name of the source file.
2) The path/name of the destination file. It will then append the date in dd-mm-yyyy format

*****************************
@echo off
copy %1 %2
FOR /f "tokens=2-4 delims=/ " %%a in ('DATE/T') do SET date=%%a-%%b-%%c
rename %2 "%2 %date%"
*****************************

<< JOC >>
 
oops - that should be (note it removes any file extensions) :-
rename %2 &quot;%~n2 %date%%&quot;

If you want to keep the file extension of the original filename used as parameter 1 use:-
rename %2 &quot;%~n2 %date%%~x1&quot;

If you want to specify a file extension as part of the name in parameter 2 use:-
rename %2 &quot;%~n2 %date%%~x2&quot;

<< JOC >>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top