Click to See Complete Forum and Search --> : [RESOLVED] Simple batch file problem...
manu.patel
March 12th, 2007, 03:15 AM
Hi All, :)
I have a very simple problem, I want to create a Batch File for DOS, which rename an existing file by current Date and Time Stamp.
For e.g.
If the current Date/Time is 12th Mar 2007 15:30:00
Old File Name : abc.txt
New File Name : abc__12032007153000
Please help me out... :confused:
Zachm
March 12th, 2007, 04:03 AM
I did something like this a while ago, here's a piece of the batch:
::Parse the time variable into timeStamp
FOR /F "tokens=1-4 delims=/:. " %%J IN ("%time%") DO SET timeStamp=%%J_%%K_%%L
::Parse the dat variable into dateStamp
FOR /F "tokens=2-4 delims=/:. " %%J IN ("%date%") DO SET dateStamp=%%J_%%K_%%L
::Create the file name (will have spaces after each variable value
set filename=Performance_%dateStamp%_%timeStamp%.log
::Parse the filename again and get rid of the spaces
::FOR /F "tokens=1-4" %%J IN ("%filename%") DO SET filename=%%J%%K%%L
Hope that helps :)
manu.patel
March 12th, 2007, 04:24 AM
Hi,
Thanks for ur reply, actually i am not able to understand the code, as i want to create a Batch File in DOS for Windows.
Will this code run???
Zachm
March 12th, 2007, 04:33 AM
Yes, it creates a file named: Performance_%time-stamp%.log
It's pretty close to what you intended to do - slight modifications needed.
It IS a batch file to run under windows.
Best of luck !
manu.patel
March 12th, 2007, 05:08 AM
Hi Zachm,
I have tried but its not working. :cry:
I think I should more eleborate the issue: :rolleyes:
I have a file name abc.txt in "D:\Paths" path
Now I want to rename this file as abc_<CurrentDate>_<CurrentTime>.txt thru batch
Zachm
March 12th, 2007, 05:24 AM
This worked for me under WinXP:
::Parse the time variable into timeStamp
FOR /F "tokens=1-4 delims=/:. " %%J IN ("%time%") DO SET timeStamp=%%J_%%K_%%L
::Parse the dat variable into dateStamp
FOR /F "tokens=2-4 delims=/:. " %%J IN ("%date%") DO SET dateStamp=%%J_%%K_%%L
::Create the file name (will have spaces after each variable value
set filename=abc_%dateStamp%_%timeStamp%.txt
rename D:\paths\abc.txt %filename%
Output file was: abc_03_12_2007_11_22_37.txt
manu.patel
March 12th, 2007, 06:37 AM
Thanks a Million, it works... :D
Sensi12002
October 28th, 2009, 02:11 PM
I just used this code as well...Thanks, I have been trying to correct an issue for a few days
rename "D:\proj\RGP5\backup\log.txt" %date:~-4,4%%date:~-10,2%%date:~-7,2%%time2%.txt
This code snipit would not work before 10:00 in the morning on Windows XP. I believe it was because of the blank space it would insert when it was 9:45 " 945".
Thanks again
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.