38

Is it possible to use robocopy to copy only the files that do not exist in destination?

robocopy has a /is (include same files) switch. What I am looking for is an /xs switch. If a file exists in both the source and the destination I don't want it to be copied. The criteria is file name only, regardless of modified day, size, etc. For example, even if the source has a newer file (based on modified date) than the same file in the destination, I don't want it to be copied. Possible to do this? Thanks.

Oliver Salzburg
  • 86,445
  • 63
  • 260
  • 306
yky
  • 381
  • 1
  • 3
  • 3

2 Answers2

48

Just use the /xc (exclude changed) /xn (exclude newer) and /xo (exclude older) flags:

robocopy /xc /xn /xo source destination 
Harry Johnston
  • 5,754
  • 7
  • 30
  • 55
  • 1
    That does not work (at least if you have other options as well - i.e. /b /e /copyall). Robocopy looks at timestamp and I believe even if the last accessed time stamp is different, it will copy. If there is a way, would love to know about it. –  Nov 21 '12 at 02:49
  • The /xn and /xo options should prevent robocopy from copying because of a different timestamp. Worked fine when I tested it. Robocopy does not pay attention to the last accessed timestamp. Your answer will probably be removed (because it isn't an answer) but you can email me if you want to discuss this. – Harry Johnston Nov 21 '12 at 03:41
  • 4
    Use /FFT if you copy between different filesystems (NTFS, FAT). It should prevent Robocopy from thinking that a file is older/newer while it is actually the same date and time. – Martin Oct 22 '14 at 09:44
  • @HarryJohnston, I have a script that runs in a .bat file and it seems to copy the files but overwrites the file in the destination folder. What I want to know is how do I get this script to move the files and in the destination folder add a timestamp as part of the destination file name ? `START /WAIT robocopy %EFM_EXPORT% %EFM_TEMP% *.CFX /S /NP /R:5 /W:5 /XX /XD *PR *PA *TA *DC *Bypass /MOV /LOG:%EFM_MOVE%` – DJ KRAZE Sep 01 '16 at 16:52
  • @DJKRAZE: I don't think you can do that with robocopy; there's no provision for renaming the files as they are copied/moved. You could probably do it in batch language if you wanted (with the `move` command providing the underlying functionality) though personally I'd prefer almost anything else, Powershell or cscript perhaps if you don't want to use a compiled language. But if you have to use batch there are plenty of batch-language experts on Stack Overflow. – Harry Johnston Sep 01 '16 at 21:26
  • I think I will do this with PowerShell as a last resort but C# I can have this done in 5 mins.. thanks.. I was just trying to help someone – DJ KRAZE Sep 01 '16 at 21:57
  • 6
    Worth adding the `/s` switch as well otherwise it won't enter directories if they already exist. – Tom Carpenter Jul 16 '17 at 18:03
  • @Tom, the OP didn't say whether he wanted a recursive copy or not. It isn't always desirable. – Harry Johnston Jul 16 '17 at 21:28
  • @HarryJohnston Sure, I was just noting it in the comments for anyone finding the answer later on as I did. – Tom Carpenter Jul 16 '17 at 22:12
  • I like to suggest: robocopy /xc /xn /xo /s /R:0 /W:0 source destination – Codebeat Nov 01 '19 at 02:04
  • @Codebeat, I recommend /R:0 only under special circumstances. Normally, if a network glitch causes a file copy to fail, you want it to be retried. – Harry Johnston Nov 01 '19 at 10:43
-1

If you're copying from left to right, you want to only copy orphaned files on the left to the right side.

I use a pay tool called Beyond Compare that handles these type of scenarios. RoboCopy is great for mapped drives or even UNC paths, but my two use cases involves:

  • FTP to copy new files to my web site
  • move/archive files to DropBox

That, I unfortunately can not do with RoboCopy.

Sun
  • 6,192
  • 10
  • 34
  • 54