Page 1 of 1

How to rename a file with date/time?

Posted: 14 Feb 2011 08:26
by dominion
Hi,

how is it possible to rename a file with current date and time.
i'm trying this but it's not working.

please help:

Code: Select all

@echo off
color 4
set N=
(for /f "tokens=1-5 delims=:" %%d in ("%time%") do ceho rename
file.txt file%%d-%%e-%%f.txt)


i'm using xp and Win7
pause

Re: How to rename a file with date/time?

Posted: 14 Feb 2011 08:39
by dominion
I found it but:

ren file.txt file%date:~0,2%%date:~3,2%%time:~0,2%%time:~3,2%.txt

i'm looking how to add day and second
thanks

Re: How to rename a file with date/time?

Posted: 14 Feb 2011 08:52
by dominion
I modify the previous code to:

r

Code: Select all

en file.txt file-%date:~0,2%-%date:~3,2%-%date:~6,4%-%time:~0,2%-%time:~6,2%-%time:~0,2%.txt

but when current is : 15:50:00
the file name is: file-14-02-2011-15-58-00 ?? why?

the time is incorect why?

thank you

Re: How to rename a file with date/time?

Posted: 14 Feb 2011 08:55
by dominion
Sorry for disturbance i made mistake.
now it's working well

Code: Select all

ren file.txt file-%date:~0,2%-%date:~3,2%-%date:~6,4%-%time:~0,2%-%time:~3,2%-%time:~6,2%.txt


Thank Dominion and have a nice week.