[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Adding todays date to file names

Posted on 2008-10-07
7
Medium Priority
?
334 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 1020 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 980 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 5

Assisted Solution

by:si_shamil
si_shamil earned 1020 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 980 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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

873 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