• 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

thanks
0
jmason218
Asked:
jmason218
  • 2
1 Solution
 
MoliereCommented:
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.
0
 
jmason218Author Commented:
Thanks but I would like to run just a simple batch and not add in another program.
0
 
anetworkCommented:
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.

Phew!

0
 
jmason218Author Commented:
Thanks for the Help...
0

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