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?

  • I'd expect it to just go alphabetically... and why does it matter which order files are copied in anyways?
    – Robert Rouhani
    Jan 13, 2012 at 8:02
  • if problem occurs to my aap...it should copy the latest file first
    – user373083
    Jan 13, 2012 at 8:04
  • 1
    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, 2012 at 8:08
  • 2
    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, 2012 at 8:14
  • 1
    @RobertRouhani One reason it might matter is if it's not alphabetically it can be really hard to eyeball and get an idea if your copy is going to finish on time.
    – Michael
    Oct 7, 2022 at 19:07

2 Answers 2


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.


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.

  • 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, 2012 at 8:20
  • 1
    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: codecodex.com/wiki/Bubble_sort
    – Gambrinus
    Jan 13, 2012 at 9:56
  • 2
    calling robocopy once for each file kind of defeats the whole point of the application, does it not?
    – Michael
    Oct 7, 2022 at 21:17

You must log in to answer this question.