Solved

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

Posted on 2008-10-23
4
673 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 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