Hello
I would like to have a batch file that adds a time stamp to a folder name if finds it in the directory.
For example. I have a folder that has folder names like this:
03-11-2013
03-12-2013
03-12-2013
if the script finds a folder with todays date . it will add a time stamp to it.
please see example below
03-11-2013
03-12-2013_20-52-43 <-- todays date
03-12-2013_22-45-30 < -- next time the batch file ran and found new folder created with todays date.
So when the script ran it found a folder with 03-12-2013 (todays date) it add the time stamp after it. and then later the script found another folder that was created and add the time stamp. etc....etc...
batch file to change folder name with time stamp
Moderator: DosItHelp
Re: batch file to change folder name with time stamp
Your date format is ambiguous. Is it MM-DD-YYYY?
Where does the timestamp come from?
Where does the timestamp come from?
Re: batch file to change folder name with time stamp
Yes
date format is MM-DD-YYYY . the dated folder is place there by another program that does a different process.
Timestamp should be current system time. any format of the time layout is acceptable.
thanks Mike
date format is MM-DD-YYYY . the dated folder is place there by another program that does a different process.
Timestamp should be current system time. any format of the time layout is acceptable.
thanks Mike
Re: batch file to change folder name with time stamp
Here we go:
Code: Select all
@echo off &setlocal
set "startfolder=X:\PathTo\start"
pushd "%startfolder%"
for /d %%i in (*.*) do call:process "%%~i"
popd
goto:eof
:process
set "fname=%~nx1"
set "fname=%fname:~0,10%"
if "%fname%" neq "%date%" goto:eof
set "fname=%fname%_%time%"
set "fname=%fname::=-%"
ren "%~1" "%fname%"
goto:eof
endlocal
Last edited by mfm4aa on 22 Mar 2013 04:45, edited 1 time in total.
Re: batch file to change folder name with time stamp
The %date% may not be what is needed as regional settings affect it. Using WMIC is a good option.
It shouldn't walk the directory tree, according to the request...
It shouldn't walk the directory tree, according to the request...
Re: batch file to change folder name with time stamp
My code doesn't make any assumptions about the date format (except the length of 10).
I removed the /r option from the for loop & added pushd/popd, thanks.
I removed the /r option from the for loop & added pushd/popd, thanks.
Re: batch file to change folder name with time stamp
mfm4aa wrote:My code doesn't make any assumptions about the date format (except the length of 10).
%date% can have a day name in the string, and may not be in MM-DD-YYYY format.
using Wmic to get the date is region insensitive. Using VBS and Richie Lawrence's code are also options for get the date in a predictable manner.