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
Solved

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

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

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…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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