3

To update the files in the destination folder, I'd like to copy only the newer files whose older version are already in the destination folder.

I don't want to copy any files that are in the source folder but not in the destination folder.

This way, I'd not increase the number of files in the destination folder, only updating the existing files in the destination folder.

Example:

  • Source directory:

    A.txt   2020-08-25  
    B.txt   2020-09-13  
    C.txt   2020-05-03  
    
  • Destination directory:

    B.txt   2020-08-09  
    C.txt   2020-05-03  
    

In this case, only B.txt should be copied because:

a) A.txt Doesn't exist in the destination folder, so, don't copy it,
b) B.txt In the destination folder is older, so, copy it,
c) C.txt In the destination isn't older, so don't copy it.


  • Can RoboCopy do this, or I need a batch file?
Io-oI
  • 9,237
joehua
  • 307

2 Answers2

1

many ideas here in this link for the same issue if you need to copy only the new data to the destination folder Robocopy command to copy updated files and long path names

IT Pro
  • 11
1

Disclaimer: I was looking for exactly the same problem when I found this question. I'm somewhat surprised to find the answer only in a comment to a not-accepted answer, so I'm essentially just re-iterating what Steve Rindsberg commented above.

Using XCOPY SrcFolder [DstFolder] /U /D [/E] is doing exactly what was asked for, with:

  • SrcFolder being the repository folder containing newer files
  • DstFolder being were to copy to (and where to look up what to copy). This is optional if the command is run from within DstFolder
  • /U Copies only files that already exist in destination.
  • /D Copies files whose source time is newer than the destination time.
  • /E Extend this like-for-like copy to sub-directories.

I also found it useful to just output what will be copied (without actually doing it), for which one can use

XCOPY SrcFolder [DstFolder] /U /D [/E] /Y /F /L

  • /L Displays files that would be copied.
  • /Y Suppresses prompting to confirm you want to overwrite an existing destination file.
  • /F Displays full source and destination file names while copying.
BmyGuest
  • 456