Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my C# application, I am using robocopy for with option /s for copying sub folders also.

Suppose I have files & folders from the last month.

Which file will it copy first, the latest one or the older one?

Is there any way that we can specify that it should copy the old file first or vice versa?

share|improve this question

migrated from Jan 13 '12 at 23:55

This question came from our site for professional and enthusiast programmers.

I'd expect it to just go alphabetically... and why does it matter which order files are copied in anyways? – Robert Rouhani Jan 13 '12 at 8:02
if problem occurs to my should copy the latest file first – user373083 Jan 13 '12 at 8:04
Alphabetically... or anyway you can't relay on what it copies first or last. Also support Robert, why does it matter? – Regfor Jan 13 '12 at 8:04
it matters to my app....thats why i want know.....& know if is there any option with that i can control it? – user373083 Jan 13 '12 at 8:08
actually my source folder is 20GB big log, & i want the copy the recent logs first.... if any problem occurs in between then atleast user should get the recent logs. – user373083 Jan 13 '12 at 8:14

robocopy will copy the files and directories first, that it first gets from the OS. If you want a specific order - you have to take care of that:

  • list your files
  • order them by date
  • call robocopy for each file

that should solve your problem.

share|improve this answer
if i ordering them by date....which files or directories it takes first the latest ones or the older ones? I want my recent my recent file or directories to be copied first...what can i do? – user373083 Jan 13 '12 at 8:20
depends on how you order them - the ordering algorithm should be implemented by you - so you do a bubblesort, quicksort, etc. on the last-modification date. here you can find an implementation of a bubblesort: – Gambrinus Jan 13 '12 at 9:56

If you want to copy newer (recent) files first, you could use the Robocopy /MAXAGE:n and /MINAGE:n command line options.

You will have to run Robocopy 2 or more times (depending on how much you want to control the file copy order by the "age" of the files).

Here is information about the /MAXAGE:n and /MINAGE:n command line options:

/MAXAGE:n :: MAXimum file AGE - exclude files older than n days/date.
/MINAGE:n :: MINimum file AGE - exclude files newer than n days/date.
    (If n < 1900 then n = n days, else n = YYYYMMDD date).

In the simplest case for example, you could first copy files that are AT-MOST 1 day old, then when that is finished, copy all files that are AT-LEAST 1 day old. Here are the 2 Robocopy command lines for this (first) example:

First run of Robocopy:
    robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:1
Second run of Robocopy:
    robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MINAGE:1

If you want more control than that, you can combine the 2 options. For example:

  1. First copy all files that are AT-MOST, 1 day old
  2. Then copy files that are AT-LEAST 1 day old, and AT-MOST 2 days old
  3. Then copy files that are AT-LEAST 2 days old, and AT-MOST 3 days old
  4. Then copy files that are AT-LEAST 3 days old, and AT-MOST 5 days old
  5. Then copy files that are AT-LEAST 5 days old (all remaining filea)

Here are the Robocopy command lines for this (second) example:

robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:1
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:2 /MINAGE:1
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:3 /MINAGE:2
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:5 /MINAGE:3
robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MINAGE:5

If you want to see the order that Robocopy will use to copy the files, you could use the /L option:

robocopy "C:\source\path" "C:\dest\path" /S /COPY:DAT /DCOPY:T /MAXAGE:1 /L

With the /L option, Robocopy will just list the files that "would" be copied, but will not actually copy any files.

share|improve this answer

You must log in to answer this question.