• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2907
  • Last Modified:

How can I force robocopy to copy files from the oldest date to the newest date

How can I force robocopy to copy files from the oldest date to the newest date? I have noticed by default it does newest file to oldest file.
0
sqlagent007
Asked:
sqlagent007
  • 3
1 Solution
 
Shift-3Commented:
Please explain further and give some examples of what you're trying to accomplish.
0
 
sqlagent007Author Commented:
If I have files named:

a.txt
b.txt
c.txt

Does Robocopy start with A and move to Z or does it go by datestamp?
0
 
Shift-3Commented:
Going by its logfiles, it appears to go through files alphabetically by default.  I don't know of any native switches to change the order in which files are copied.  

You could use a FOR loop to cycle through the output of DIR|SORT and copy files one-by-one that way.
0
 
Shift-3Commented:
Come to think of it, dir /O would be better.  Something like this:

@echo off
setlocal

set source=c:\folder1
set dest=d:\folder2

for /F "usebackq tokens=*" %%G in (`dir "%source%" /A:-D /B /O:D`) do (
 robocopy "%source%" "%dest%" "%%G" /ZB
)

endlocal
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now