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 code | Meaning | Error? |
|---|---|---|
0 | No files were copied. Source and destination are already identical. No failures. | No |
1 | One or more files were copied successfully. No failures. | No |
2 | Extra files or directories exist in the destination that are not in the source. No files were copied (no changes needed). | No |
3 | Files were copied (bit 1) and extra files exist in destination (bit 2). | No |
4 | Mismatched files or directories were found. Inspect the output — some files may not have been copied. | No |
5 | Files were copied (bit 1) and mismatched files were found (bit 4). | No |
6 | Extra files (bit 2) and mismatched files (bit 4) were found. No files copied. | No |
7 | Files copied (bit 1), extra files found (bit 2), mismatched files found (bit 4). All informational. | No |
8 | Some files or directories could not be copied. At least one copy failure occurred. | Yes |
16 | Fatal error. Robocopy did not copy any files. Check source path, destination path, and permissions. | Yes |
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
%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"
$? 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.
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
| Column | What it means | Action needed? |
|---|---|---|
| Copied | Files transferred in this run | No — expected |
| Skipped | Files already up to date in destination | No — expected |
| Mismatch | Files with conflicting attributes or timestamps | Investigate if non-zero |
| FAILED | Files that could not be copied after all retries | Yes — check log for details |
| Extras | Files in destination not present in source | No — 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
- robocopy — Microsoft Learn — full command reference including the exit code bitmask table
Related tools
- ROBOCOPY Command builder
- Windows Command Line (CMD) Cheat Sheet — quick reference for batch scripting patterns used with Robocopy
- PowerShell Commands Cheat Sheet — PowerShell exit code handling and script patterns
Related guides
- ROBOCOPY command in Windows — full command reference with all practical flags and examples
- How to backup files with ROBOCOPY — backup patterns including scheduled task setup and log handling
- How to sync two folders with ROBOCOPY — sync patterns and when to use /MIR vs /E