Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
Rename File with Timestamp in 24hrs
Name: mafl Date: November 26, 2003 at 12:03:24 Pacific OS: NT 4.0 CPU/Ram: intel
Comment:
I need to rename a file appending the timestamp of the system in this format: yyyymmddhhmmss Example: convert crexp.txt to crexp20031126144543.txt
I was using this: for /f "tokens=2-4* delims=/ " %%a in ('DATE /T') do set THEDATE=%%c%%b%%a for /f "tokens=1* delims=: " %%a in ('time /T') do set THETIME=%%aa%%bb%%cc%%dd ren %1 %~n1%THEDATE%%THETIME%%~x1
however this does not give hours in 24hrs format, nor does it give me seconds
Name: IVO Date: November 26, 2003 at 12:46:06 Pacific
Reply:
If you post me the exact output you get typing
Command /C Ver | Time
I can solve your trouble.
0
Response Number 2
Name: mafl Date: November 26, 2003 at 13:21:08 Pacific
Reply:
the output of C:\>Command /C Ver | Time The current time is: 16:20:49:84 Enter the new time: Incorrect MS-DOS version The system cannot accept the time entered. Enter the new time: C:\>
0
Response Number 3
Name: IVO Date: November 26, 2003 at 13:47:08 Pacific
Reply:
The output I expected is
The current time is: 16:20:49:84 Enter the new time:
neater than you posted. However try to replace your previous
for /f "tokens=1* delims=: " %%a in ('time /T') do set THETIME=%%aa%%bb%%cc%%dd ren %1 %~n1%THEDATE%%THETIME%%~x1
with the following
For /F "tokens=2-4 delims=:" %%a in ('Command /C Echo. ^| Time ^| Find "current"') Do Set THETIME=%%a%%b%%c Set THETIME=%THETIME:~1% ren %1 %~n1%THEDATE%%THETIME%%~x1
If anything goes, wrong post again.
0
Response Number 4
Name: mafl Date: November 28, 2003 at 06:48:34 Pacific
Reply:
What I am supposed to get with your suggestion above?
so far I have entered the command as it is above, tweaked it in all manners and I always get error messages: like syntax error, /c is not a recognized internal o external command, etc.
0
Response Number 5
Name: IVO Date: November 28, 2003 at 07:14:20 Pacific
Reply:
The statement beginning For /F ends on the third line with %%a%%b%%c without new lines between. I suggest you highlight, copy and paste into your NotePad the lines I posted to be sure to get them integer.
The statement must work in a batch file.
Report to me what's the result.
0
Response Number 6
Name: mafl Date: December 1, 2003 at 10:52:20 Pacific
Reply:
Your suggestion work fine. I just made some adjustments to substring the output. The problem was that I got confused with the circumflex accents before the pipe command. I took out this and it work all fine. Thanks,
Summary: Hi I need to run a batch file which will move a file to a location while renaming it. I got the moving part but can't figure out how to get the date and 24 hour added to the file name. ...
Summary: How do I rename a file with the current date? eg test.txt to text20030422.txt -------------- for /F %%A in ("%DATE%") do ren test.txt test%%C%%A%%B.txt I used the command to renmae my text file, but t...
Summary: I have tried lots of ways to rename files by using a batch file but I can not add prefixes to the my old file names by using wild cards. Is there a way to rename with wild cards as the samples below. ...