jeudi 1 décembre 2016

IF/ELSE returning multiple error levels in batch

Good afternoon, I am attempting to copy a directory to another directory, and have the whole process reported in the log. Right now, the log gets a report of success AND a 9009 error.

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
    )

previous to this I do whats below to confirm the folder 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

The files get moved, but it still gets hung up on error code 9009. So confused. I use cmtrace to monitor the log and once batch hits that 9009 it closes leaving about 10 more things left to do.

Aucun commentaire:

Enregistrer un commentaire