在我的批处理文件中,我有一个if语句,这是行为不端。我错过了哪些是造成这种情况的原因?批处理语句不起作用
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
)
这是它是如何表现:当移动类型==文件,它贯穿,如果声明就好了,但是,当移动式==目录,脚本死了,没有做任何事情。
当if语句切换(目录第一,第二的文件)目录中的作品和文件不
您发布的代码没有任何问题。问题必须出现在您未显示的代码中。也许你有一些不平衡的括号。 – dbenham
@dbenham - 我更新了两条if语句中的所有代码 – staples
上面的代码是否在另一个循环中? – foxidrive