Yes its .bat file
Main Topics
Browse All TopicsAll,
I'm writing a MSDOS BATCH script and need to add CURRENT DATE & TIME to the filename when copying to another folder. Pls help!
Thanks,
Chandru.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
well, it should all be on one line - perhaps that much is obvious, but it cut-n-pasted to two lines from your post.
Also, I just noticed that I accidentally swapped the day and the month, so it should be this instead:
copy a.txt c:\batch\myfile_%date:~10,
so the only change i made was to swap the 4 and the 7 (to switch the month and day), and made it all one line.
Thanks Knight for the quick response. You see as 2 lines due to command line window size. In place of copy and paste, i typed the whole syntax and still the same error. :(
C:\>copy a.txt c:\batch\myfile_%date:~10,
me:~3,2%%time:~6,2%.txt
The syntax of the command is incorrect.
ah-ha! lol, you're going to love this...
if you look at the whole filename you will see a space, because it is before 10am where you are. Do this:
@echo c:\batch\myfile_%date:~10,
so, let me just work out how to get rid of that space and I'll get right back to you...
right, so the only way I know to remove that is to set it in a separate variable first, and then substitute the space for a zero:
set today=%date:~10,4%%date:~4
set rightnow=%time:~0,2%%time:
@ech
copy a.txt c:\batch\myfile_%today%_%r
Great, It works now.... :) Thank you for the quick response & solution, Good that I approached you before my time becomes double digit and would have found command worked again fine... ;)
C:\>set today=%date:~10,4%%date:~4
C:\>set rightnow=%time:~0,2%%time:
C:\>set rightnow=%rightnow: =0%
C:\>
C:\>@echo The file will be: c:\batch\myfile_%today%_%r
The file will be: c:\batch\myfile_20091112_0
C:\>copy a.txt c:\batch\myfile_%today%_%r
1 file(s) copied.
Business Accounts
Answer for Membership
by: JeffPartonPosted on 2009-11-06 at 09:46:38ID: 25761254
Does it have to be DOS?