Computing.Net > Forums > Disk Operating System > Rename File with Timestamp in 24hrs

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

Reply to Message Icon

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



Sponsored Link
Ads by Google

Response Number 1
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

Related Posts

See More



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,


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Rename File with Timestamp in 24hrs

Rename File with Timestamp in 24hrs www.computing.net/answers/dos/rename-file-with-timestamp-in-24hrs/16719.html

Rename file with current date www.computing.net/answers/dos/rename-file-with-current-date/13069.html

HELP Renaming files with a .bat file www.computing.net/answers/dos/help-renaming-files-with-a-bat-file-/3679.html