How to Batch Copy or Move files based on Extension and Date.

Last updated on March 1st, 2021

A few days ago, a client asked me to move a large set of files, based on their extension and oldness, to another location (drive), in order to save space on the source disk. After some searching, I discovered that the more reliable way to perform that task is by using Microsoft's ROBOCOPY utility.

How to Batch Copy or Move files based on Extension and Date.

This tutorial contains instructions on how you can copy or move, a large set of files to another location, by using ROBOCOPY.

How to Batch Copy or Move Files Using ROBOCOPY.

1. Open PowerShell or Command Prompt as Administrator.
2.
According the action you want to perform, give one of the corresponding commands below:

A. To copy only the files (without the subfolders), from one folder to another, give this ROBOCOPY command:

  • ROBOCOPY "source" "destination"

Example1: To copy the files of the 'C:\4test' folder, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup"

Example2: To move all the files of the 'C:\4test' folder, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" /MOVE

B. To copy all the contents (files and subfolders), from one folder to another, give this ROBOCOPY command:

  • ROBOCOPY "source" "destination" /S

Example1: To copy all the files and subfolders of the 'C:\4test' folder, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" /S

Example1: To move all the files and subfolders from the 'C:\4test' folder, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" /S /MOVE

C. To copy all the files created before a certain period, from one folder (and its subfolders), to another folder, give this ROBOCOPY command:*

  • ROBOCOPY "source" "destination" /S /MINAGE:n

* MINAGE:n = MINimum file AGE – exclude files newer than n days/date.

Example1: To copy all the old files and subfolders that are older than 180 days (6 months), from the folder 'C:\4test', to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" /S /MINAGE:180

Example2: To move all the old files and subfolders that are older than 180 days (6 months), from the folder 'C:\4test', to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" /S /MOVE /MINAGE:180

D. To copy all the files created after a specific date, from one folder (and its subfolders), to another folder, give this ROBOCOPY command:*

  • ROBOCOPY "source" "destination" /S /MAXAGE:n

* MAXAGE:n = MAXimum file AGE – exclude files older than n days/date

Example1: To copy all the newer files and subfolders created in the last 180 days (6 months), from the folder 'C:\4test', to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" /S /MAXAGE:180

Example2: To move all the newer files and subfolders which created in the last 180 days (6 months), from the folder 'C:\4test', to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" /S /MOVE /MAXAGE:180

 


E. To copy files based on their extension, from one folder to another by creating the same folder structure as in source folder, give this ROBOCOPY command:

  • ROBOCOPY "source" "destination" .FileExtension /S

Example1: To copy all the JPG files from the 'C:\4test' folder and its subfolders, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" *.jpg /S

Example2: To move all the JPG files from the 'C:\4test' folder and its subfolders, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" *.jpg /S /MOVE

F. To copy files based on their extension and their oldness, from one folder to another (by creating the same folder structure on the destination, as in source folder), give this ROBOCOPY command:

  • ROBOCOPY "source" "destination" .FileExtension /S /MINAGE:n

Example1: To copy all the JPG files which created before 180 days, from the 'C:\4test' folder and its subfolders, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" *.jpg /S /MINAGE:180

Example2: To move all the JPG files which created before 180 days, from the 'C:\4test' folder and its subfolders, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" *.jpg /S /MOVE /MINAGE:180

Example3: To copy all the JPG files which created at the last 180 days, from the 'C:\4test' folder and its subfolders, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" *.jpg /S /MAXAGE:180

Example4: To move all the JPG files which created at the last 180 days, from the 'C:\4test' folder and its subfolders, to the folder 'F:\4testbackup', the command is:

  • ROBOCOPY "C:\4test" "F:\4testbackup" *.jpg /S /MOVE /MAXAGE:180

 

That's it! Let me know if this guide has helped you by leaving your comment about your experience. Please like and share this guide to help others.

If this article was useful for you, please consider supporting us by making a donation. Even $1 can a make a huge difference for us in our effort to continue to help others while keeping this site free: