rename a file according to current date.

Hello All,

I just joined the exchange today and I'm not sure what premium service I can afford at this time, so I only have 75 points to offer. (and do not want to offend anyone lol)

I need to create an automated process of renaming a file based on the current date. For example, If the current date was 03-12-03 I need to rename the file to include the date of the day before 03-11-03. The file naming convention would go something like this FILENAME.TXT => FILENAME031103.TXT

I am not very good with writing scripts:( So I am not sure on how to go about this task.

Much appreciated,
sr12
silverram12Asked:
Who is Participating?
 
CeLLuSConnect With a Mentor Commented:

-----------------------------
@ECHO OFF
FOR /F "tokens=2" %%i IN ('date /t') DO SET thedate=%%i
SET mm=%thedate:~0,2%
SET dd=%thedate:~3,2%
SET yyyy=%thedate:~6,4%
)

SET /S dd= %dd%-1
RENAME FILENAME.TXT "FILENAME%mm%-%dd%-%yyyy%.txt"
-----------------------------

Open notepad paste the code above without the ------- and substitute the FILENAMEs on the bottom line with the real filename.  Save the notepad file as anything you want example: RX.BAT

Make sure that this batch file is in the same directory as the file to be renamed.

Try it and let me know
0
 
silverram12Author Commented:
CeLLuS,

Thanks for getting back to me. The script you wrote worked like a charm! But it renames the file with the current not the date from the day before. Can you rename a file with the date of the day before the current date?

Thanks again

sr12
0
 
CeLLuSCommented:
silverram12

Change "SET /S dd=%dd%-1" to "SET /A dd=%dd%-1" no quotes.
Sorry about that

Cell
0
 
silverram12Author Commented:
CeLLuS,

You da man! Thanks a million, Seeing the type of response to what (to me) was a difficult question gives me no other choice but to sign up for the premium service. :-)

again much appreciated,

sr12



0
 
CeLLuSCommented:
silverram12,

I'm glad I could help.

Good luck,

Cell

0
All Courses

From novice to tech pro — start learning today.