Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi, I wish to rename a log file by appending the date to the end of the file name.
This is what it is named now: log.txt
This is what I want to rename it to using today's date of 09/18/2005: log09182005.txt
After searching this forum I found a previous poster had gotten a reply how to do this in Windows 2K. I tried the suggested command for Windows 2K in my Windows XP Home:
ren log.txt log_%date:~4,2%-%date:~7,2%-%date:~12,2%.txt
and got an error "The syntax of the command is incorrect".
Might anyone know the correct format of this command for Windows XP ?
Appreciate your help !
Carl

Hi Carl,
Ut's not so much a w2k/xp issue as it is about the way your DATE is formatted.
Mine is:
Mon 19-09-2005
So I can:
echo %date:~10,4%%date:~7,2%%date:~4,2%
and get:
20050919
If at first you don't succeed, you're about average.M2

Hi M2,
Thanks !! Say that worked just fine !!
For the sake of completeness if anyone else ever reads this thread, the proper DOS command to rename:
before: C:/mysqlback/log.txt
after: C:/mysqlback/log09192005.txt
is the DOS command:
ren c:\mysqlback\log.txt log%date:~10,4%%date:~7,2%%date:~4,2%.txt
Please note that ren wants the full path.
Thanks again M2 !!
Carl

Hi Carl,
Yeah, well, you either need to specify the file location or you need to change to the drictory where the file is.
cd c:\mysqlback
If at first you don't succeed, you're about average.M2

For the sake of completeness if anyone else ever reads this thread, the proper DOS command to rename:
before: C:/mysqlback/log.txt
after: C:/mysqlback/log09192005.txt
is the DOS command:
ren c:\mysqlback\log.txt log%date:~4,2%%date:~7,2%%date:~10,4%.txt
You can change the order of the date around easily enough to suit yourself.
Thanks again M2 !!
Carl

![]() |
Image placeholders
|
Error messages
|

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