这是重写的批处理文件,以正确处理所有错误条件(希望未完全测试) .
@echo off
REM Backup files first and report any errors if not successful
%SystemRoot%\System32\xcopy.exe "C:\channels\filetransfer_process\*" "C:\channels\backup\" /C /Q /Y >"%TEMP%\%~n0.tmp"
REM Error checking
REM Note: The environment variable ERRORLEVEL contains the
REM return code of the last executed program or script.
if errorlevel 5 SET "BODY=File write error occurred" & GOTO MailError
if errorlevel 2 SET "BODY=Not enough memory or free space" & GOTO MailError
if not errorlevel 1 pause
set "FileCount=0"
for /F "usebackq" %%I in ("%TEMP%\%~n0.tmp") do set "FileCount=%%I"
if "FileCount" == "0" SET "BODY=No files were found to copy" & GOTO MailError
RE