下午好,我正在尝试将目录复制到另一个目录,并在日志中报告整个过程。现在,日志获得成功报告和9009错误。
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
)
在此之前,我在下面做了什么确认文件夹exsists;
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 :(得分: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 prompt prompt $Q$Q$G$S
)