2016-12-01 5 views
0

午後、別のディレクトリにディレクトリをコピーしようとしていて、ログ全体にプロセスが報告されています。今のところ、ログは成功の報告と9009のエラーを取得します。複数のエラーレベルをバッチで返すIF/ELSE

C:\Windows\System32\xcopy.exe /E /I /Y "\\network_share\program\source\*" "C:\Program Files\program" 
    IF %errorlevel% EQU 0 (echo %DATE% - %TIME% - Success!!! >> \\network_share\program\logs\%username%.log) 
    ELSE (
    echo %DATE% - %TIME% - failure - %errorlevel% >> \\network_share\program\logs\%username%.log 
    Exit /b 1 
    ) 

これに先行して、私はフォルダエキスティストを確認するために以下を行います。

IF EXIST "C:\program files\program" (echo %DATE% - %TIME% - program folder already exsists >> \\network_share\program\logs\%username%.log 
    ELSE (
    md "C:\Program Files\program" 
    echo %DATE% - %TIME% - Folder didn't exist but may now %errorlevel% >> \\network_share\program\logs\%username%.log 

ファイルは移動しますが、エラーコード9009でハングアップします。混乱します。私はcmtraceを使ってログを監視し、一度バッチヒットしたら9009が終了し、残りの約10個が残ります。

答えて

0

読むIF /?

確か
The ELSE clause must occur on the same line as the command after the IF. For 
example: 

    IF EXIST filename. (
     del filename. 
    ) ELSE (
     echo filename. missing. 
    ) 

、あなたの例では、エラーコード9009は意味の両方で:

==> ELSE 
'ELSE' is not recognized as an internal or external command, 
operable program or batch file. 

==> echo %errorlevel% 
9009 

を(==>は私cmd.exe command promptprompt $Q$Q$G$Sでその文字列に注意してください)

+0

うん、私がいましたしかし、それは本当にありがとうございました。ありがとうございました。 – Greensystemsgo

関連する問題