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>


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:


Lubos Hrasko · January 25, 2020 at 11:39 am

TIP – test any robocopy command without the /MOVE flag to make sure files are being copied correctly before first

vikas khandola · March 21, 2018 at 5:13 am

use robocopy

Randall · August 14, 2017 at 1:34 pm

BE CAREFUL!!! I did this and was left with nothing but 0 byte files in the _ToBeDeleted folder.

Questions or Comments?