|
Question : Rename file with previous weekday's date as the file name
|
|
Experts,
having some trouble getting a concise answer on this:
I have a folder- C:/folder with a file- sampledailyfile.txt
and another folder- C:/otherfolder
today's date is- 10/31/2006
I would like my batch (.bat) script to open "folder", take sampledailyfile.txt, rename it as 10302006.txt, and save it to "otherfolder"
if this occurs on a monday, the file name should use friday's date (e.g. on 10/30/2006 the file it finds should be named 10272006.txt
any ideas?
thanks~!!!
|
|
Answer : Rename file with previous weekday's date as the file name
|
|
:: rename a folder to a date that is today or few days ago @echo off setlocal set D=%date% set y=%D:~10,4% set m=%D:~4,2% set dw=%D:~0,3% set d=%D:~7,2% set folder=c:\folder\ set file=sampledailyfile.txt if not "%dw%"=="Mon" echo ren %folder%%file% %y%%m%%d%&goto :eof
----- But to subtract a few days from the date, I've applied the complex code from http://www.experts-exchange.com/Q_21994705.html "Setting the Date in a Batch file - Is there a better way?", to make this demo: http://www.sendspace.com/file/e2fbc6 ToDate.bat
|
|
|
|