Adding todays date to file names

Is there an easy way to add todays date to file names using .CMD

I want to copy all the files in a folder and create copies with today's date added to the file name

The folder would contain
test.txt
test2.txt
and after running the .cmd file the folder would contain
test.txt
test2.txt
test10072008.txt
test10072008.txt

thanks for the help
 
derekstattinAsked:
Who is Participating?
 
si_shamilConnect With a Mentor Commented:
copy & paste this code to CMD file
@echo off
for %%i in (*.txt) do (copy %%i %%~ni%date:~-10,2%%date:~-7,2%%date:~-4,4%.txt)

Open in new window

0
 
sirbountyConnect With a Mentor Commented:
or a shorter method...
xcopy "*.txt" "*%date:/=%.*"

Open in new window

0
 
derekstattinAuthor Commented:
I did not have any results from sir bounty's solution, but si_shamils works.

Is there a way to add dashes into the code 10-07-2008?

thanks for the help on the other question as well

I am a beginner and I am trying to build the peices so I understand how to achieve the outcome I am looking for. I will post a couple more question that will build on your answers
0
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

 
si_shamilConnect With a Mentor Commented:
with dashes:
@echo off
for %%i in (*.txt) do (copy %%i %%~ni%date:~-10,2%-%date:~-7,2%-%date:~-4,4%.txt)

Open in new window

0
 
sirbountyConnect With a Mentor Commented:
Had a type-o in my code...try this:
xcopy "*.txt" "%date:/=-%.*"

Open in new window

0
 
derekstattinAuthor Commented:
Thanks for the help,
I will post another question shorlty
0
 
derekstattinAuthor Commented:
0
All Courses

From novice to tech pro — start learning today.