SOLVED: How To MOVE Files Based On Their Age using RoboCopy
Below is a script of how to MOVE files to a folder based on their age:
ROBOCOPY <source> <destination> /MOVE /E /MINAGE:<number_of_days> /CREATE /R:1 /W:1 /XD <folders_you_want_to_omit>
Sample:
ROBOCOPY E:\ E:\_ToBeDeleted /MOVE /E /MINAGE:21 /CREATE /R:1 /W:1 /XD E:\COMPANY_PICS E:\_ToBeDeleted
The translation of this command is:
- ROBOCOPY E:\ – look at the E: Drive, we could have entered a drive letter AND a folder for this instead
- E:\_ToBeDeleted – apply the results to the E:\_ToBeDeleted folder
- /MOVE – move the files
- /E – everything including empty directories
- /MINAGE:21 – only files that are 21 days or older – a useful alternative here is /MINLAD which is Last Access Date
- /CREATE – create the folder structure and move the files
- /R:1 – retry once if the file is in use
- /W:1 – wait 1 second if the file is in use
- /XD – exclude the COMPANY PICTURES folder and the destination folder
Another way to handle this is using the FORFILES command which we have documented: urtech.ca/2015/07/solved-command-line-batch-to-delete-files-based-on-their-age/
This website uses cookies.
View Comments
TIP - test any robocopy command without the /MOVE flag to make sure files are being copied correctly before first
use robocopy
BE CAREFUL!!! I did this and was left with nothing but 0 byte files in the _ToBeDeleted folder.
Randall,
by running the following command, all files & folder copied... but size 0 byte.
robocopy source Destination /CREATE /E /minage:30
what is the root cause and fix ?
the CREATE flag creates the moved files as 0 size. No fix.
To move the full files, omit the /create