Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

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
 
0
derekstattin
Asked:
derekstattin
  • 3
  • 2
  • 2
4 Solutions
 
si_shamilCommented:
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
 
sirbountyCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
si_shamilCommented:
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
 
sirbountyCommented:
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
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.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now