robocopy - when does it delete files from destination?

2

2

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?

J. Fabian Meier

Posted 2017-02-23T14:46:25.480

Reputation: 159

no answer to the question, but why don't you just use xcopy or copy-item? it would overwrite all old files in the destination, but not delete files which are only present in the destination. like copy-item c:\source\* c:\destination -force – SimonS – 2017-02-23T14:59:04.383

Answers

4

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.

Dabrovnijk

Posted 2017-02-23T14:46:25.480

Reputation: 61