Robocopy to copy only new folders and files

You can add /S for that. You don't need the \E which is for copy empty directories. You won't even need the \XO which is done by the \MAXAGE.

/S :: copy Subdirectories, but not empty ones.

When no files are copied in a directory, the directory is not created on the destination.

robocopy c:\users\valery\documents j:\robocopy /S /MAXAGE:20131030 /XD {directories_to_exclude}

If you don't have directories to exclude you can just use:

robocopy c:\users\valery\documents j:\robocopy /S /MAXAGE:20131030

You can do a robocopy /? for all the help.

 /S :: copy Subdirectories, but not empty ones.
 /E :: copy subdirectories, including Empty ones.
 /XD dirs [dirs]... :: eXclude Directories matching given names/paths.
 /XO :: eXclude Older files.
 /MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.

My simple commands that works wonderful is:

RoboCopy.exe  "\\\SourceServer\Folder" "X:\WEB" /copy:datso /mir /fft /r:0 /w:0 /secfix /mt:20 /xo /xf thumbs.db /log+:X:\TON-FS4.log /nc /ns /np /ndl /nfl /tee

Explanation:

  • X:\WEB is my destination folder.
  • Switches:
    • /copy:datso: Specifies the file properties to copy:
      • (d: Data, a: Attributes, t: Time stamps, s: NTFS access control list (ACL), o: Owner information)
    • /mir: Mirrors a directory tree
    • /fft: Assumes FAT file times, important when copying data
    • /r:0: Number of retries on failed
    • /w:0: Wait time between retries 0 seconds
    • /secfix: Fixes file security on all files, even skipped ones
    • /mt:20: Creates 20 threads copies
    • /xo: Excludes older files - if destination file exists and is the same date or newer than the source - don't bother to overwrite it.
    • /xf thumbs.db: Excludes "thumbs.db" files (path) you can use wild characters here (ei: *.mp3)
    • /log+:filename.log: Writes the status output to the specified log file
    • (appends to the existing log file) or to use a new log just /log:filename.log

Not this particular case but I hope that will help someone when they do file servers migration.


robocopy.exe "Q:\TEST" "T:\TEST" /E /XO /LOG+:"T:test.log

Just to break this down for bertieb - this code is meant to run straight from command line and not in a bat script.

Set Source & Destinations:

robocopy.exe "Q:\TEST" "T:\TEST"

"Q:\TEST" = Sets The Source Directory to Mapped Drive "Q"

"T:\TEST" = Sets The Destination Directory to Mapped Drive "T"

OPTIONS USED:

/E /XO /LOG+:"T:test.log"
  1. /E : Copy Subdirectories Including Empty Ones
  2. /XO : Exclude older files
  3. LOG+ : This will log the robocopy process in a .log file named test that will be in the root directory of the destination (i.e. Above the "TEST" folder on T). LOG+ will append the output status to the test.log file rather than over write it.

SIDE NOTE:

The LOG+ option can be switched to the LOG option if you would like to only have the most recent session's information saved.

Easy to read version of more information on Robocopy or the Microsoft documentation.