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/

View Comments

Published by
Ian Matthews

This website uses cookies.