?
Solved

rename a file according to current date.

Posted on 2003-03-12
5
Medium Priority
?
272 Views
Last Modified: 2010-04-13
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
0
Comment
Question by:silverram12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 

Accepted Solution

by:
CeLLuS earned 300 total points
ID: 8124336

-----------------------------
@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
 

Author Comment

by:silverram12
ID: 8127958
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
 

Expert Comment

by:CeLLuS
ID: 8130745
silverram12

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

Cell
0
 

Author Comment

by:silverram12
ID: 8131312
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
 

Expert Comment

by:CeLLuS
ID: 8133777
silverram12,

I'm glad I could help.

Good luck,

Cell

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question