Skip to content

Instantly share code, notes, and snippets.

@aromig
Created September 28, 2016 14:47
Show Gist options
  • Save aromig/19871c003952b04f6c78299b816e98b7 to your computer and use it in GitHub Desktop.
Save aromig/19871c003952b04f6c78299b816e98b7 to your computer and use it in GitHub Desktop.
Robocopy - Exclude Existing Files
robocopy c:\Sourcepath c:\Destpath /E /XC /XN /XO
:: /E makes Robocopy recursively copy subdirectories, including empty ones.
:: /XC excludes existing files with the same timestamp, but different file sizes. Robocopy normally overwrites those.
:: /XN excludes existing files newer than the copy in the source directory. Robocopy normally overwrites those.
:: /XO excludes existing files older than the copy in the source directory. Robocopy normally overwrites those.
:: With the Changed, Older, and Newer classes excluded, Robocopy will exclude files existing in the destination directory.
@jbhutchens
Copy link

Well, that was a nice copy and paste. Thank you for posting it!

@oliva1337
Copy link

amazing

@mpniel
Copy link

mpniel commented Dec 26, 2018

Wouldn't it be simpler less stupid to have a special swith to exclude existing files instead of adding tree different ones to do the same job?

@JeffCave
Copy link

@mpniel robocopy is a syncronization utility. That means that not copying files that are different would be strange. In that context, not comparing files at all is the weird edge case. The ability to turn off each type of difference check one at a time is the more useful scenario.

(I say that having come here looking for a way to turn off all the checks in one go)

@raghavsanadhya
Copy link

raghavsanadhya commented Jun 25, 2024

#ALL files were copied and no OVERWRITING ONLY IF SOURCE FILE WAS ACCESSED BEFORE THE LAST TIME DESTINATION FILE WAS ACCESSED

IT MIGHT NOT WORK FOR EVERY CASE

$robocopyArgs = "/log:D:\robocopywithnflndllogs\output.log" + " /XO /XX /S /E /ZB"
Start-Process -FilePath "C:\Windows\System32\Robocopy.exe" -verb runAs -ArgumentList "$source", "$destination", $robocopyArgs -Wait

#neither extra files at destination should be deleted
#neither files at destination should be overwritten (meaning: if files at destination are edited then should not be overwritten)
#all extra files at source should be copied to destination

@martin12333
Copy link

/xn Source directory files newer than the destination are excluded from the copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment