15

Objective: To find all new files and subfolders under some root folder (let us say Documents) and to copy them to another disk (J: in this case).

Command line used:

robocopy c:\users\valery\documents j:\robocopy /XO /E /MAXAGE:20131030 /XD

Result: A full folders tree is created. Only new files copied, which is the way it's supposed to work. Good so far.

A point is that I do not want to create all subfolders on a target disk if there are no new files in them.

Results are acceptable, but there is a lot of work to go through all folders and to find new files, as well as to understand what subfolders are a new ones.

4 Answers 4

14

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.
5
  • Thanks a lot for the answer, first of all! This is not a problem - not to copy empty sub-folders. I know aboout /s. What is /xd at this location in a command line? Maybe I did not point my problem correctly. When I use my command line the whole directory (folders) tree is created on a target disk. Then only "new" files will be copyed into appropriate folders. It means, that most of folders will be empty on the target disk. As I wrote, there is no so huge problem to enter folder after folder and to find where are "new" files, but is a fool work. Nov 8, 2013 at 21:12
  • Sorry for a previous comment! I did not pay attention on /XD near /S. It works!!!!!!! I know about /S, but what does mean ?xd in this context? I feel its location in a command line is critical. I did not understand this parameter from robocopy documentation, sorry Nov 8, 2013 at 21:22
  • You used the /XD so i assumed you would exclude some directories. BTW you don't need the /E which is for empty directories. You can replace that one with the /S. You won't even need /XO which is done by the /MAXAGE. I'll change it in my question. You add directories you want to exclude after /XD, if any otherwise you can delete the parameter.
    – Rik
    Nov 8, 2013 at 21:31
  • I understood my fault. I did not realise that in /S ",but not empty ones" means also a case, when a source folder is not a "real empty folder" , but rather "a pseudo empty" - one, that does not contain files, created after defined date. Thank you very much one more time! Valery Nov 8, 2013 at 22:10
  • I think the documentation could be improved to describe the /s switch as "copy Subdirectories, but do not create empty ones" which would be much clearer for situations like this
    – AdamV
    Mar 24, 2021 at 12:43
6

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.

1
  • 1
    /w:0 is redundant if you're already using /r:0 as there are no retries for it to wait between. You can just use /r:0 by itself and it will do exactly the same thing as /r:0 /w:0. Oct 15, 2019 at 20:54
1
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.

0
1
robocopy.exe "Q:\TEST" "T:\TEST" /E /XO /LOG+:"T:test.log"
1
  • 8
    Can you add an explanation?
    – bertieb
    Mar 1, 2017 at 18:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .