在我的批處理文件中,我有一個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