Solved

Rename a file using a batch script to have date and time

Posted on 2008-10-23
4
669 Views
Last Modified: 2012-06-27
I am trying to use a batch script to rename a file to have date and time. So far I am able to add the date but cannot figure out how to get the time also. Below is what I have so far that works.


for /f "tokens=1-5 delims=/ " %%d in ("%date%") do rename "pa.txt" pa%%g%%e%%f.txt
0
Comment
Question by:edensandavant
  • 3
4 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 125 total points
ID: 22789998
You could add time in the same way:

for /f "tokens=1-9 delims=/: " %%d in ("%date% %time%") do echo rename "pa.txt" pa%%g%%e%%f%%h%%i.txt

I think, off hand!

I tend to use

set datetime=%date:/=%%time::=% for a quick and dirty date/time

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 22790018
Remove the "echo" there once happy with the filename of course...
0
 

Author Comment

by:edensandavant
ID: 22790761
That worked perfectly. Thanks.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 22791362
No problem... just splits up at the : in the time aswell as the original / for dates.

Steve
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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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