5

I want to overwrite older files in the destination but not delete files which are only present in the destination.

From https://ss64.com/nt/robocopy.html I understood that /XO might do exactly that but I also understood that it is possible to delete files from the destination (if they have no counterpart in the source). When exactly does this second behaviour (which I want to avoid) occur?

2 Answers2

11

When you use either one of two options:

  • /PURGE : Delete dest files/folders that no longer exist in source.
  • /MIR : MIRror a directory tree - equivalent to /PURGE plus all subfolders (/E)

example:

  • robocopy /PURGE c:\source d:\destination
  • robocopy /MIR c:\source d:\destination

Then you will delete files in the destination if they do not exist in the source.

Robocopy will also default to "By default Robocopy will only copy a file if the source and destination have different time stamps or different file sizes."

I would also suggest that you look into:

  • /COPY:copyflag[s] : What to COPY (default is /COPY:DAT) (copyflags : D=Data, A=Attributes, T=Timestamps S=Security=NTFS ACLs, O=Owner info, U=aUditing info).

example:

  • robocopy /COPY:DAT c:\source d:\destination

That will make sure you get the same timestamps for the files that will be copied.

1

If you use /PURGE and also have /XX in your options then PURGE will not delete files or folders because /XX makes Robocopy ignore them. Remove /XX from your options and Purge will work and each deleted file will be shown in the log as an *EXTRA File. Directories will be shown as *EXTRA Dir. The Extras will be deleted from the destination address

Maxjonz
  • 11