• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1758
  • Last Modified:

batch file - rename with system date -1

I need to look for a file every day that system date -1

example file (system date is 2003-03-05) I am looking for is:

pos.20030304.c1315 and I want to rename the file to pos20030304.txt

  • 2
1 Solution
For batch renaming, I use a program called The Rename. It is freeware and can be obtained at http://www.herve-thouzard.com/therename.phtml

Otherwise, you could do it with VBScript.
jmason218Author Commented:
Thanks but I would like to run just a simple batch and not add in another program.
Your have two problems:
1) Cannot do maths in a script (eg count=count-1)
2) If the day is 1, and you subtract one, the date could ne 31, 30, 29 (in a leap year) or 28.  Likeise for the month 01, etc.

Solution: run a batch today that itself creates a bacth file that records todays date.  Then, run this new batch file tomorrow.  Something like this:

for /f "tokens=1,2,3,4 delims=/ " %%i in ('date /t') do SysDate=%%l%%j%%k
echo set %sysdate-1% > %sysdate%.bat
call sysdate-1.bat
for %%a in (*.%sysdate-1%.*) do ren %%a %sysdate-1%.txt
ren sysdate.bat sysdate-1.bat

NB this records dates in UK format; adjust variables etc for US format.

Script needs checks to stop it renaming sysdate.bat too soon - but now you have the variable SysDate that should be easy.  If not, let us know.


jmason218Author Commented:
Thanks for the Help...

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now