1.

Solve : DOS Batch File Programming Question?

Answer»

I need to add a command to automatically burn a file on to a dvd, using a program called CommandBurner, to a backup batch file we currently have. Anyway, I just need to know how to fix this IF statement so it does what I need.

This is what the case statement basically has to do:

If the date is either 01-07 AND the DAY is Tuesday, then execute this command.

This is what I have so far:
Code: [SELECT]set day=%date:~3,2%

if /i %day LSS 07 && %dayoftheweek% EQU Tuesday goto burn

:burn
cd d:\Autoback\CommandBurner\
CmdBurn burn /d d:\Autoback\Daily\ /l %today% /ejectQuote

If the date is either 01-07 AND the day is Tuesday, then execute this command.

This is ambigous. Do you know what "either" means? I presume you meant "both".

I also presume you are getting the day of the week from somewhere.

Code: [Select]set day=%date:~3,2%

set num=0
if "%day%"=="07" set /a num=1
if "%dayoftheweek%"=="Tuesday" set /a num=%num%+1

if %num% EQU 2 goto burn
goto noburn

:burn
cd d:\Autoback\CommandBurner\
CmdBurn burn /d d:\Autoback\Daily\ /l %today% /eject
goto end

:noburn
echo not burning

:end

Thanks for the response. In your statement 'if "%day%"=="07" set /a num=1', what I'm trying to do with the numbers 01-07 is make sure it's the first Tuesday of the month. That's why I use the first 7 days of the week. Is your statement covering all 7 days, or is it only covering the 7th? Will it work if I do this:

Code: [Select]if "%day%"<="07" set /a num=1Quote from: Barnicle on January 14, 2009, 07:41:36 AM
Thanks for the response. In your statement 'if "%day%"=="07" set /a num=1', what I'm trying to do with the numbers 01-07 is make sure it's the first Tuesday of the month. That's why I use the first 7 days of the week. Is your statement covering all 7 days, or is it only covering the 7th? Will it work if I do this:

Code: [Select]if "%day%"<="07" set /a num=1

no.
No, it won't work, or no your original statement covers on the 7th day? If so, how can I cover the days from 01, 02, 03...07 You cannot use <= to test for "less than or equal to", is what I meant. That is not correct batch language syntax.Code: [Select]@echo off
REM Clearly, you are using US date format
REM That is mm/dd/yyyy

REM You need to do a numeric test, so use set /a to make the
REM day variable a numeric one BUT...
REM set /a interprets numbers beginning with a 0 as being octal
REM so we have to filter out any leading 0 since 08 and 09 are
REM (obviously!) not valid octal numbers and will cause an error and the
REM batch will halt.

REM test if first digit of day is a zero
REM if yes just use 2nd digit

if "%date:~3,1%"=="0" (
set /a day=%date:~4,1%
) else (
set /a day=%date:~3,2%
)

REM You don't get AND in batch, so we
REM have to simulate it.
REM set num to 0
set /a num=0

REM if day is less than or equal to 7, add 1 to num
if %day% LEQ 7 set /a num=%num%+1

REM if today is Tuesday, add 1 to num
if "%dayoftheweek%"=="Tuesday" set /a num=%num%+1

REM if num now equals 2 then both tests are satisfied
if %num% EQU 2 goto burn
goto noburn

:burn
echo Day is Tuesday and date is 7th or earlier
echo Therefore burning...
echo I sure hope there's a writable disk in that burner!
echo Press a key when ready...
pause > nul
cd d:\Autoback\CommandBurner\
CmdBurn burn /d d:\Autoback\Daily\ /l %today% /eject
goto end

:noburn
echo not burning

:endExcellent. You the man!Code: [Select]echo Day is Tuesday and date is 7th or earlier
Note that I changed this line because I think that <= symbols may screw with the batch execution.

Sorry, but I don't see where "dayoftheweek" is getting set. Can that be extracted from %DATE% somehow?

Thanks.Quote from: swgivens on March 04, 2009, 03:40:04 PM
Sorry, but I don't see where "dayoftheweek" is getting set. Can that be extracted from %DATE% somehow?

Thanks.

It isn't being set in that script. The original poster has some way of getting the day of the week which was not specified.

Visual Basic Script has a method of getting the day of the week name.

to swgivens, here is one of the many methods to get dayoftheweek.

Code: [Select]@goto start
o70 06
i71
o70 07
i71
q

:start
@echo off & setlocal enabledelayedexpansion
for /f "skip=1" %%a in ('debug ^< %~f0^|find /v "-"') do set x=!x!%%a
for /l %%a in (301,1,307) do if 0%%a==%x% goto:burn
echo %x%:no burn for today
goto:eof

:burn
echo %x%:its tuesday and date^<^=07, put burn code here

note: 03 for tuesday, 01 for sat.
maybe someone might find this code useful in the future.


Discussion

No Comment Found