Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

BAT File Rename with Date Problem

1 view
Skip to first unread message

Joe D

unread,
Jul 26, 2009, 9:05:01 PM7/26/09
to
I have a bat file that is supposed to rename a file with the month and date.
(It looks to see if the final file exists and then deletes it. Then renames
the file "File.xls" to "file 72009.xls")

Lines 5-8 are repeated for 5 differnt files and seems to work for some and
not for others.

Does anyone have any suggestions to simplify this and make it more robust?
(For instance can "a" and "b" be saved and reused instead of repeating the
"For...." comand?)


1- rem @echo off
2 - set inc=12
3 - set Scr=c:\TempVBS.vbs
4 - echo WScript.Echo DateAdd("h", %inc%, Now()) > %Scr%

5 - for /F "tokens=1,3 delims=/ " %%a in ('cscript //nologo %Scr%') do if
not exist "C:\file %%a%%b.xls" goto nofile
6 - for /F "tokens=1,3 delims=/ " %%a in ('cscript //nologo %Scr%') do del
"C:\file %%a%%b.xls"
7 - :nofile
8- for /F "tokens=1,3 delims=/ " %%a in ('cscript //nologo %Scr%') do ren
"C:\file.xls" "file %%a%%b.xls"

9 - del %Scr%


--
Joe D

0 new messages