Solved

Adding todays date to file names

Posted on 2008-10-07
7
322 Views
Last Modified: 2010-04-16
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
Comment
Question by:derekstattin
  • 3
  • 2
  • 2
7 Comments
 
LVL 5

Accepted Solution

by:
si_shamil earned 255 total points
ID: 22665037
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
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 245 total points
ID: 22665087
or a shorter method...
xcopy "*.txt" "*%date:/=%.*"

Open in new window

0
 

Author Comment

by:derekstattin
ID: 22665256
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 5

Assisted Solution

by:si_shamil
si_shamil earned 255 total points
ID: 22665268
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
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 245 total points
ID: 22665275
Had a type-o in my code...try this:
xcopy "*.txt" "%date:/=-%.*"

Open in new window

0
 

Author Comment

by:derekstattin
ID: 22665313
Thanks for the help,
I will post another question shorlty
0
 

Author Comment

by:derekstattin
ID: 22665449
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question