FG
💻 Software

Getting ROBOCOPY to return a "proper" exit code?

Fresh5 days ago
Mar 15, 2026130037 views
Confidence Score1%
1%

Problem

Is it possible to ask ROBOCOPY to exit with an exit code that indicates success or failure? I am using ROBOCOPY as part of my TeamCity build configurations, and having to add a step to just silence the exit code from ROBOCOPY seems silly to me. Basically, I have added this: to the script that is being run. However, this of course masks any real problems that ROBOCOPY would return. Basically, I would like to have exit codes of 0 for SUCCESS and non-zero for FAILURE instead of the bit-mask that ROBOCOPY returns now. Or, if I can't have that, is there a simple sequence of batch commands that would translate the bit-mask of ROBOCOPY to a similar value?

Error Output

EXIT /B 0

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: Getting ROBOCOPY to return a "proper" exit code?

Low Risk

TechNet suggests this one-liner to convert the exit code into a more traditional exit code: Or this to ignore the exit code completely (i.e. don't care if it failed or succeeded): However, both commands above will terminate a script after the robocopy has executed. This is an issue especially for CI builds. If you want to use robocopy in this scenario, you need to set the error code manually for irrelevant exit codes. Below, all error codes below 8 will be rewritten to no error at all, and the …

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment