--- In email@example.com
, Aristos Vasiliou <aristos@...> wrote:
> I am currently using this batch file to daily backup my documents on my second hard disk. XCOPY /Y /E /D /C %USERPROFILE%\Documents\*.* D:\Backup\Documents
> What I need to do is modify the batch file so that it won't overwrite D:\Backup\Documents, but create a new folder named D:\Backup\Documents_Monday and then on Tuesday create a new folder named D:\Backup\Documents_Tuesday and so on.
> It should do this for the whole week, so that if I make a mistake today, and discover it after two days, I can restore from three days back. And then on Monday it can overwrite again.
> How can I do this?
Many years ago, I wrote a very small command line program named Weekday.exe (see http://www.incodesystems.com/PRODUCTS/WEEKDAY.HTM)
that sets the ERRORLEVEL to a number that corresponds to the day of the week. We use that to create batch files that behave differently based on the day of the week. All you do is:
IF ERRORLEVEL 7 GOTO Sat
IF ERRORLEVEL 6 GOTO Fri
IF ERRORLEVEL 5 GOTO Thu
IF ERRORLEVEL 4 GOTO Wed
IF ERRORLEVEL 3 GOTO Tue
IF ERRORLEVEL 2 GOTO Mon
IF ERRORLEVEL 1 GOTO Sun
A simpler way would be to deference the ERRORLEVEL pseudo environment variable, like this:
Here's another way to get a similar result, without the WeekDay.exe program.
FOR /F "usebackq delims==" %%i IN (`DATE /T`) DO SET WeekDay=%%i
We have written a large number of helper programs that effectively extend the functionality of batch files (see http://www.incodesystems.com/PRODUCTS/BATCH.HTM)
. These programs can be used to create batch files that appear to the user like they are running a Windows program. A relatively new one, named Echox.exe (see http://www.incodesystems.com/PRODUCTS/ECHOX.HTM)
, can be used to echo text to the screen in color and at X,Y locations specified on the command line. It also allows you to echo text without ending with a carriage return, line feed sequence, so the cursor remains on the end of the text. We are always looking for suggestions to improve our offering of batch file helper programs.