ROBOCOPY exit codes explained



Robocopy does not use a standard pass/fail exit code. It uses a bitmask — a number where each bit represents a different outcome, and multiple bits can be set at the same time. This means a non-zero exit code does not indicate failure, and zero does not always mean the job did what you expected. Understanding the exit code system is essential the moment Robocopy runs inside a script, a scheduled task, or a monitoring tool that checks for non-zero return values.

The most common symptom of not understanding this: a Task Scheduler job shows “Last Run Result: 0x1” and gets flagged as failed — when in reality it completed successfully and copied files without errors.


Quick answer

Exit codes 0–7 are not errors. Exit codes 8 and above are errors. In a batch script:

robocopy C:\Source D:\Destination /E /R:3 /W:5
if %ERRORLEVEL% GEQ 8 echo Robocopy reported errors

Exit code reference

Exit codeMeaningError?
0No files were copied. Source and destination are already identical. No failures.No
1One or more files were copied successfully. No failures.No
2Extra files or directories exist in the destination that are not in the source. No files were copied (no changes needed).No
3Files were copied (bit 1) and extra files exist in destination (bit 2).No
4Mismatched files or directories were found. Inspect the output — some files may not have been copied.No
5Files were copied (bit 1) and mismatched files were found (bit 4).No
6Extra files (bit 2) and mismatched files (bit 4) were found. No files copied.No
7Files copied (bit 1), extra files found (bit 2), mismatched files found (bit 4). All informational.No
8Some files or directories could not be copied. At least one copy failure occurred.Yes
16Fatal error. Robocopy did not copy any files. Check source path, destination path, and permissions.Yes
Note: Exit codes are additive bitmasks. Code 3 means bits 1 and 2 are both set — files were copied AND extra files exist in destination. Code 9 would mean files were copied (bit 1) and a copy failure occurred (bit 8). In practice, codes above 8 are rare but possible when multiple conditions apply simultaneously.

Handling exit codes in batch scripts

The correct pattern for checking Robocopy results in a batch script is to test whether the exit code is 8 or higher — not whether it is non-zero.

@echo off
rem robocopy-check.bat — run Robocopy and handle exit codes correctly
rem Save to C:\bat\robocopy-check.bat

robocopy C:\Source D:\Destination /E /R:3 /W:5 /LOG+:C:\bat\robocopy-log.txt /NP

rem Store exit code before any other command resets ERRORLEVEL
set ROBOCOPY_EXIT=%ERRORLEVEL%

rem Codes 0-7: informational only — not errors
if %ROBOCOPY_EXIT% LEQ 7 (
    echo Robocopy completed. Exit code: %ROBOCOPY_EXIT%
    exit /b 0
)

rem Code 8+: actual copy failures occurred
echo Robocopy failed. Exit code: %ROBOCOPY_EXIT%
echo Check C:\bat\robocopy-log.txt for details.
exit /b 1
Common mistake: Reading %ERRORLEVEL% after an echo or if statement. Both commands reset ERRORLEVEL to 0 on success, which overwrites the Robocopy exit code before you can check it. Always capture the exit code into a variable immediately after Robocopy runs: set ROBOCOPY_EXIT=%ERRORLEVEL%.

Handling exit codes in PowerShell

In PowerShell, Robocopy exit codes are available via $LASTEXITCODE. The same threshold applies — 8 or above is an error.

robocopy C:\Source D:\Destination /E /R:3 /W:5 /LOG+:C:\bat\robocopy-log.txt /NP

# $LASTEXITCODE holds the Robocopy exit code
# 0-7: informational, not errors
# 8+:  copy failures occurred

if ($LASTEXITCODE -ge 8) {
    Write-Error "Robocopy failed with exit code $LASTEXITCODE. Check C:\bat\robocopy-log.txt"
    exit 1
}

Write-Host "Robocopy completed. Exit code: $LASTEXITCODE"
Note: PowerShell’s $? automatic variable reflects whether the last command returned exit code 0. Since Robocopy returns 1 on a successful copy, $? will be $false even when the job succeeded. Always use $LASTEXITCODE for Robocopy — never $?.

Fixing Task Scheduler false failures

Task Scheduler treats any non-zero exit code as a failure by default. A Robocopy job that successfully copies files returns exit code 1, which Task Scheduler displays as “Last Run Result: 0x1 (1)” — making it look like something went wrong.

The fix is to wrap Robocopy in a batch script that translates the exit code before returning to the scheduler:

@echo off
rem wrapper.bat — normalize Robocopy exit codes for Task Scheduler
rem Task Scheduler sees 0 (success) or 1 (failure) — not Robocopy's bitmask

robocopy C:\Source D:\Destination /E /MIR /R:3 /W:5 /LOG+:C:\bat\robocopy-log.txt /NP

rem Capture exit code immediately
set RC=%ERRORLEVEL%

rem Codes 0-7 are success — return 0 to Task Scheduler
if %RC% LEQ 7 exit /b 0

rem Code 8+ is failure — return 1 to Task Scheduler
exit /b 1

Register this wrapper script as the Task Scheduler action instead of calling Robocopy directly. The scheduler will now show success (0x0) for completed jobs and failure (0x1) only when Robocopy reports actual copy errors.

Result: Task Scheduler shows “Last Run Result: 0x0 (0)” for successful Robocopy runs. Alerts and monitoring tools that watch for non-zero exit codes no longer trigger false positives.

Reading the log summary

The exit code tells you whether errors occurred. The log summary tells you what happened in detail. Every Robocopy run ends with a summary block that looks like this:

rem Robocopy summary output — appears at the end of every run
               Total    Copied   Skipped  Mismatch    FAILED    Extras
    Dirs :       210         5       205         0         0         1
   Files :      3847        83      3764         0         2        14
   Bytes :   8.21 g    512.3 m    7.72 g         0    4.11 m   22.18 k
ColumnWhat it meansAction needed?
CopiedFiles transferred in this runNo — expected
SkippedFiles already up to date in destinationNo — expected
MismatchFiles with conflicting attributes or timestampsInvestigate if non-zero
FAILEDFiles that could not be copied after all retriesYes — check log for details
ExtrasFiles in destination not present in sourceNo — informational (unless /MIR)

The only column that always requires attention is FAILED. A non-zero value here means files were not copied. The log file will contain the specific file paths and the reason — typically an access denied error, a sharing violation, or a path that exceeded MAX_PATH.


Official documentation

Related tools

Related guides