Page 1 of 1

Issue with IF statement

Posted: 10 Jun 2011 10:50
by empireapathy
Hi. I'm new to working with Batch files and I seem to be having an issue with this If statement. This is a pretty basic backup script but the idea is I want to do a full backup mirroring a directory every day and then save a unique version of the database files every Saturday.

No matter what %dow% is, the IF statement is evaluating as true. I even echo %dow% at the end to confirm that it's getting set properly and it does seem to be.

Code: Select all

@ECHO OFF

FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET Today=%%B
FOR /F "TOKENS=*" %%A IN ('TIME/T') DO SET Now=%%A

set month=%Today:~0,2%
set day=%Today:~3,2%
set year=%Today:~6,4%
set hour=%Now:~0,2%
set minute=%Now:~3,2%
set amPm=%Now:~6,2%

ROBOCOPY "C:\Program Files (x86)\sugarcrm-6.1.3\\" "\\linkstation\sugarBackup\dailyBackup\\" /MIR /COPY:DT /FFT /LOG+:"C:\Users\*****\Work\Sugar Batch File\logs\sugarBackupLog"%year%%month%%day%%amPm%%hour%%minute%".txt"

FOR /f %%a in ('date /t') do set dow=%%a

if %dow%=="Sat" goto SAT else goto END
::Also tried if %dow%==Sat and got the same results.

:SAT
ROBOCOPY "C:\Program Files (x86)\sugarcrm-6.1.3\mysql\data\mysql\\" "\\linkstation\sugarBackup\weeklyBackup\savedMysql"%year%%month%%day%%amPm%%hour%%minute%"\\" /MIR /COPY:DT /FFT /LOG+:"C:\Users\*****\Work\Sugar Batch File\logs\saved\mysqlBackupLog"%year%%month%%day%%amPm%%hour%%minute%".txt"
ROBOCOPY "C:\Program Files (x86)\sugarcrm-6.1.3\mysql\data\sugarcrm\\" "\\linkstation\sugarBackup\weeklyBackup\savedSugar"%year%%month%%day%%amPm%%hour%%minute%"\\" /MIR /COPY:DT /FFT /LOG+:"C:\Users\*****\Work\Sugar Batch File\logs\saved\sugarBackupLog"%year%%month%%day%%amPm%%hour%%minute%".txt"
echo. %dow%
pause
:END


I appreciate any help. Thanks!

Re: Issue with IF statement

Posted: 10 Jun 2011 11:10
by allal
i don't see any day displaying in the output of date /t


the output is

Code: Select all

10/06/2011


where is the day,it doesn't exist

and you must code it as

Code: Select all

FOR /f %%a in ('date /t') do set "dow=%%~a"
if "%dow%"=="Sat" (goto SAT) else goto END


or

Code: Select all

FOR /f %%a in ('date /t') do set "dow=%%~a"
if "%dow%"=="Sat" (goto SAT) else (goto END)


not

Code: Select all

FOR /f %%a in ('date /t') do set dow=%%a
if %dow%=="Sat" goto SAT else goto END

Re: Issue with IF statement

Posted: 10 Jun 2011 14:13
by empireapathy
allal wrote:

Code: Select all

FOR /f %%a in ('date /t') do set "dow=%%~a"
if "%dow%"=="Sat" (goto SAT) else goto END



This worked perfect. I just needed to throw the parentheses around goto SAT and it worked perfect. Thanks!