Solved

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

Posted on 2008-10-23
4
679 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

695 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