In my batch file I have an if statement which is misbehaving. What am I missing which is causing this?
if "%moveType%"=="file" (
echo Arcval File Move 1>>"%logfile%" 2>&1
if not exist %arcval_folder% (
mkdir %arcval_folder%
echo Directory: %arcval_folder% created. 1>>"%logfile%" 2>&1
ECHO. 1>>"%logfile%" 2>&1
)
echo xcopy "%src_dir%" "%tgt_dir%" 1>>"%logfile%" 2>&1
echo F|xcopy "%src_dir%" "%tgt_dir%" 1>>"%logfile%" 2>&1
if ERRORLEVEL 1 (
echo Failure: File not found, Arcval File not promoted. 1>>"%logfile%" 2>&1
echo "\\ntmaster\code\reskit\blat.exe" "\\ntmaster\batch\Jobs\Test\far\Common\ArcvalFailure-emailTxt.txt" -t "%promoter_email%" -c "%initiator_email%" -s "Failure! File not found, Arcval File not promoted." -f "%initiator_email%" 1>>"%logfile%" 2>&1
"\\ntmaster\code\reskit\blat.exe" "\\ntmaster\batch\Jobs\Test\far\Common\ArcvalFailure-emailTxt.txt" -t "%promoter_email%" -c "%initiator_email%" -s "Failure! File not found, Arcval File not promoted." -f "%initiator_email%" 1>>"%logfile%" 2>&1
ECHO. 1>>"%logfile%" 2>&1
echo Failure email sent, exiting program.
) else (
echo Success: Arcval File was successfully promoted. 1>>"%logfile%" 2>&1
echo "\\ntmaster\code\reskit\blat.exe" "\\ntmaster\batch\Jobs\Test\far\Common\ArcvalSuccess-emailTxt.txt" -t "%promoter_email%" -c "%initiator_email%" -s "Success! Arcval File was successfully promoted." -f "%initiator_email%" 1>>"%logfile%" 2>&1
"\\ntmaster\code\reskit\blat.exe" "\\ntmaster\batch\Jobs\Test\far\Common\ArcvalSuccess-emailTxt.txt" -t "%promoter_email%" -c "%initiator_email%" -s "Success! Arcval File was successfully promoted." -f "%initiator_email%" 1>>"%logfile%" 2>&1
ECHO. 1>>"%logfile%" 2>&1
echo Success email sent, exiting program.
)
goto end
)
if "%moveType%"=="directory" (
echo Polysystems Directory Move 1>>"%logfile%" 2>&1
if not exist %tgt_dir% (
mkdir %tgt_dir%
echo Directory: %tgt_dir% created. 1>>"%logfile%" 2>&1
ECHO. 1>>"%logfile%" 2>&1
) else (
echo ERROR: Polysystems Target directory already exists, Source was not promoted. 1>>"%logfile%" 2>&1
echo "\\ntmaster\code\reskit\blat.exe" "\\ntmaster\batch\Jobs\Test\far\Common\polySystemsErr-emailTxt.txt" -t "%promoter_email%" -c "%initiator_email%" -s "ERROR! Polysystems Target directory already exists, Source was not promoted." -f "%initiator_email%" 1>>"%logfile%" 2>&1
ECHO. 1>>"%logfile%" 2>&1
"\\ntmaster\code\reskit\blat.exe" "\\ntmaster\batch\Jobs\Test\far\Common\polySystemsErr-emailTxt.txt" -t "%promoter_email%" -c "%initiator_email%" -s "ERROR! Polysystems Target directory already exists, Source was not promoted." -f "%initiator_email%" 1>>"%logfile%" 2>&1
ECHO. 1>>"%logfile%" 2>&1
echo Failure email sent, exiting program. 1>>"%logfile%" 2>&1
exit
)
echo xcopy %src_dir% %tgt_dir% /Y /Z /C /F /E 1>>"%logfile%" 2>&1
echo F|xcopy %src_dir% %tgt_dir% /Y /Z /C /F /E 1>>"%logfile%" 2>&1
echo Success: Polysystems Directory was successfully promoted. 1>>"%logfile%" 2>&1
echo "\\ntmaster\code\reskit\blat.exe" "\\ntmaster\batch\Jobs\Test\far\Common\polySystemsSuccess-emailTxt.txt" -t "%promoter_email%" -c "%initiator_email%" -s "Success! Polysystems Directory was successfully promoted." -f "%initiator_email%" 1>>"%logfile%" 2>&1
ECHO. 1>>"%logfile%" 2>&1
"\\ntmaster\code\reskit\blat.exe" "\\ntmaster\batch\Jobs\Test\far\Common\polySystemsSuccess-emailTxt.txt" -t "%promoter_email%" -c "%initiator_email%" -s "Success! Polysystems Directory was successfully promoted." -f "%initiator_email%" 1>>"%logfile%" 2>&1
ECHO. 1>>"%logfile%" 2>&1
echo Success email sent, exiting program. 1>>"%logfile%" 2>&1
goto end
)
This is how it is behaving: when move type == file it runs through that if statement just fine, however, when the move type == directory, the script dies and does not do anything.
When the if statements are switched (directory first, file second) directory works and file doesn't