1.

Solve : Backup Batch file help?

Answer»

Ok, here is the code (don't forget to scroll, it's kinda LONG)

Code: [Select]:: backup.bat
@echo off

set $string=%date%

:: Calling the batch file that looks for the day: JSI FAQ #4192

call $contains.bat "%$string%" Mon
IF "%$answer%" EQU "Y" GOTO Monday ELSE GOTO NotMon


:NotMon
call $contains %$string% Tuesday
if "%$answer%" EQU "Y" goto Tue Else goto NoTue
goto NoTue

:NoTue
call $contains %$string% Wednesday
if "%$answer%" EQU "Y" goto Wed ELSE goto NoWed

:NoWed
call $contains %$string% Thursday
if "%$answer%" EQU "Y" goto Thu ELSE goto NoTue

:NoThu
call $contains %$string% Friday
if "%$answer%" EQU "Y" goto Fri ELSE goto Panic

:::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

:Monday
if exist mon_backup.txt del mon_backup.txt
@echo Running Monday's Backup
goto finished

:Tuesday
if exist tue_backup.txt del tue_backup.txt
@echo Running Tuesday's Backup
goto finished

:Wednesday
if exist wed_backup.txt del wed_backup.txt
@echo Running Wednesday's Backup
goto finished

:Thursday
if exist thu_backup.txt del wed_backup.txt
@echo Running Thursday's Backup
goto finished

:Friday
@echo Running Friday's backup, have a nice weekend!
if exist fri_backup.txt del fri_backup.txt
goto finished

:finished
echo.
@echo Today's backup successful
echo %$answer%
echo %$string%
goto :EOF

:Panic
@echo VALID DATE NOT FOUND
@echo Reported date is %$string%
goto :EOF

REM End Of File
And here is the problem. No matter what, it will skip to :Monday (or lower if i remove those lines) and completely ignore everythng in the middle. the first Everything after the CALL is ignored until it gets to :Monday.

The file that it is calling is located: http://www.jsifaq.com/SUBI/tip4100/rh4192.htm
-----

I am so confused, any help WOULD be appreciated!Since %date% will RETURN only 3 letters for the day you may want to change
call $contains %$string% Tuesday
to
call $contains %$string% Tue
and so on.

Or put your sunglasses on and do it SIMPLE 8-):

Code: [Select]:: backup.bat
@echo off

[highlight]goto:%date:~0,3% 2>NUL
goto:Panic[/highlight]

:::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

:Mon
if exist mon_backup.txt del mon_backup.txt
@echo Running Monday's Backup
goto finished

:Tue
if exist tue_backup.txt del tue_backup.txt
@echo Running Tuesday's Backup
goto finished

:Wed
if exist wed_backup.txt del wed_backup.txt
@echo Running Wednesday's Backup
goto finished

:Thu
if exist thu_backup.txt del wed_backup.txt
@echo Running Thursday's Backup
goto finished

:Fri
@echo Running Friday's backup, have a nice weekend!
if exist fri_backup.txt del fri_backup.txt
goto finished

:finished
echo.
@echo Today's backup successful
echo %$answer%
echo %$string%
goto :EOF

:Sat
:Sun
:Panic
@echo VALID DATE NOT FOUND
@echo Reported date is %$string%
goto :EOF

REM End Of File
Then you pull out a cigar and do it even simpler:

Code: [Select]:: backup.bat
@echo off

[highlight]set day=%date:~0,3%
goto:%day% 2>NUL
goto:Panic[/highlight]

:::::::::::::::::::::::::::::::::::::::::::::::::::::::

[highlight]:Mon
:Tue
:Wed
:Thu
:Fri
if exist %day%_backup.txt del %day%_backup.txt
echo.Running %day%'s backup[/highlight]
echo.
echo.Today's backup successful
goto :EOF

:Panic
@echo VALID DATE NOT FOUND
@echo Reported date is %day%
goto :EOF

REM End Of File
DOS IT HELP?Hey! that is simpler!!

Thanks for pointing out my mistake, I had written and rewritten it so many times trying to get it to work that I didn't even notice I changed those lines.

Can you explain exactly what is going on in the Code: [Select]goto:%date:~0,3% 2>NUL
Thank you very much for your help!Sure, here is an explanation:

See also the help for the set command here
http://dostips.cmdtips.com/DosCommandRef.htm#set

%date:~0,3%
... resolves the environment variable date and extracts 3 characters starting at position 0. Since %date% returns something like
[highlight]Fri[/highlight] 04/21/2006
this way you get the day only.

goto:%date:~0,3%
... will subsequently use the day (e.g. [highlight]Fri[/highlight]) as a label and attempt to jump to it.
However if the label doesn't exist (e.g. [highlight]Sat[/highlight]) then it would not jump anywhere but show an error. In order to avoid seeing the error on the screen, we pipe the error output into the NUL device and trash it using:
goto:%date:~0,3% 2>NUL



Discussion

No Comment Found