|
Answer» I am trying to run a batch file (testfile.cmd) in XP Pro. Inside the batch file, I want to rename a file so that it has the current date attached to the end of the file. Something like this:
REN C:\TEMP\TESTFILE.TXT TESTFILE-20060203.TXT
Is there a way to GET the current date from the DATE command and attach it to the name of the file?
Thanks in advance! Code: [Select]for /f "tokens=2-4 delims=/ " %%i in ("%date%") do ( ren c:\temp\testfile.txt testfile-%%k%%j%%i.txt )
Good luck. 8-)Thank you thank you thank you!!! I was even able to ADJUST the code to include the month as well! [smiley=thumbsup.gif]For the code that Sidewinder used, would this also work in Windows 95?Doubtful. Not even sure this will work on Win95:
Code: [Select]%comspec% /e:2048/c for %%v in (1 2) do prompt set dt$q$d$_ | find/v "$" >{t}.BAT for %%v in (call del) do %%v {t}.bat for /f "tokens=2-4 delims=/ " %%i in ("%dt%") do set thedate=%%k%%i%%j
Found this with Google (not tested) but it won't do any harm to try it:
Code: [Select]ECHO. | DATE | FIND /I "Current" > C:\BATCH\CUR-DATE.BAT ECHO @SET CUR-DATE=%%4 > C:\BATCH\CURRENT.BAT CALL C:\BATCH\CUR-DATE.BAT
You may have to change the paths, just wanted to show you there are ways to do most anything; sometimes you just have to jump thru hoops to get them done.
I'll check my snippet closet. If I find any other methods, I'll post them.
Good luck. 8-)
PS. The original reply to this post had the %%i and %%j VARIABLES half-*censored* backwards.
|