rilliam
asked on
How to Rename a file where current date get added to its name in DOS Command Prompt?
I want to make a small backup solution by using dos.
I want to create a batch file to make an automatic daily copy from a file saved on drive c:\ to drive d:\ . I don't want the file be over written and need to keep the old files.
I want to rename the file after copying where current date gets added to its name.
Here whats I tried to do but none of them worked :
A: set filename=ABCD.txt
set newfilename=%DATE%_%TIME%_ %filename%
copy C:\FOLDER\%filename% D:\FOLDER\%newfilename%
I tried with and without " "
B: copy C:\FOLDER\a.txt D:\FOLDER\a.txt
rename d:\Folder\a.txt "%dte%"
I cannot figure out what the problem is and what I should do. The OS of machine is Windows 2003 server. Should I upgrade Command Promt?
I want to create a batch file to make an automatic daily copy from a file saved on drive c:\ to drive d:\ . I don't want the file be over written and need to keep the old files.
I want to rename the file after copying where current date gets added to its name.
Here whats I tried to do but none of them worked :
A: set filename=ABCD.txt
set newfilename=%DATE%_%TIME%_
copy C:\FOLDER\%filename% D:\FOLDER\%newfilename%
I tried with and without " "
B: copy C:\FOLDER\a.txt D:\FOLDER\a.txt
rename d:\Folder\a.txt "%dte%"
I cannot figure out what the problem is and what I should do. The OS of machine is Windows 2003 server. Should I upgrade Command Promt?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. I could use your solution on Rename Command but still have problem with copying files. I had same problem "the system cannot find the file specified". I even used "" but it didn't help. I am so excited about the Rename command. It does what I want, thanks
ASKER
Thanks EB I am kind of beginner in this matter and don't know all the command yet. I surely will work with ntbackup command. thanks.
You can always use the echo command to help troubleshoot batch commands. I don't know which option is causing trouble or both. You try the following to make sure it is all lining up and also try to enter the commands manually from a command prompt. Make sure that the file path and name displayed in the Dos window matches where the file actually exits.
When I do a copy and paste from your code I get a special character - that may be your issue
When I do a copy and paste from your code I get a special character - that may be your issue
Echo Off
set filename=a.txt
set newfilename=%Date:/=%%Time::=.%.%filename%
Echo Copy File From
Echo C:\Folder\%filename%
Echo Copy To
Echo D:\Folder\%newfilename%
Copy "C:\Folder\%filename%" "D:\Folder\%newfilename%"
Pause
Or
copy C:\FOLDER\a.txt D:\FOLDER\a.txt
Echo File
Echo C:\FOLDER\a.txt
Echo Will be Renamed to
Echo a_%Date:/= % %Time::=.%.txt
REN "C:\FOLDER\a.txt" "a_%Date:/= % %Time::=.%.txt"
Pause
eb