How to bulk copy or move files based on extension and date. – wintips.org

A few days ago, a client asked me to move a large set of files, depending on their extension and age, to another location (disk) to save space on the source disk. After some searching, I found that the most reliable way to accomplish this task is to use Microsoft’s ROBOCOPY utility.

How to bulk copy or move files based on extension and date.

This guide contains instructions on how to copy or move a large set of files using ROBOCOPY.

How to bulk copy or move files with ROBOCOPY.

1. It’s open PowerShell or Command line as administrator.
2.
Depending on the action you want to perform, issue one of the following appropriate commands:

A. To copy only files (without folders) from one folder to another, issue the ROBOCOPY command:

  • ROBOCOPY “source” “destination”

Example 1: Command to copy files from folder “C:\4test” to folder “F:\4testbackup”:

  • ROBOCOPY “C:\4test” “F:\4test backup”

Example 2: Command to move all files in folder “C:\4test” to folder “F:\4testbackup”:

  • ROBOCOPY “C:\4test” “F:\4test-backup” /MOVE

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

  • ROBOCOPY “source” “destination” /S

Example 1: Command to copy all files and subfolders of folder “C:\4test” to folder “F:\4testbackup”:

  • ROBOCOPY “C:\4test” “F:\4test-backup” /S

Example 1: Command to move all files and subfolders from folder “C:\4test” to folder “F:\4testbackup”:

  • ROBOCOPY “C:\4test” “F:\4test-backup” /S /MOVE

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

  • ROBOCOPY “source” “destination” /S /MINAGE:n

* MINAGE: n = MINIMUM file AGE – Exclude new files from n days/dates.

Example 1: Command to copy all old files and subfolders older than 180 days (6 months) from folder “C:\4test” to folder “F:\4testbackup”:

  • ROBOCOPY “C:\4test” “F:\4test-backup” /S /MINAGE:180

Example 2: Command to move all old files and subfolders older than 180 days (6 months) from “C:\4test” folder to “F:\4testbackup” folder:

  • ROBOCOPY “C:\4test” “F:\4test-backup” /S /MOVE /MINAGE:180

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

  • ROBOCOPY “source” “destination” /S /MAXAGE:n

* MAHAGE: n = MAXimum file AGE – exclude files older than n days/dates

Example 1: Command to copy all new files and subfolders created in the last 180 days (6 months) from folder “C:\4test” to folder “F:\4testbackup”:

  • ROBOCOPY “C:\4test” “F:\4test-backup” /S /MAXAGE:180

Example 2: A command to move all new files and subfolders created in the last 180 days (6 months) from the “C:\4test” folder to the “F:\4testbackup” folder:

  • ROBOCOPY “C:\4test” “F:\4test backup” /S /MOVE /MAXAGE:180

E. To copy files from one folder to another based on their extension, issue the following ROBOCOPY command to create the same folder structure as the source folder:

  • ROBOCOPY “source” “destination” .FileExtension /S

Example 1: Command to copy all JPG files from folder “C:\4test” and its subfolders to folder “F:\4testbackup”:

  • ROBOCOPY “C:\4test” “F:\4test backup” *.jpg /S

Example 2: Command to copy all JPG files from folder “C:\4test” and its subfolders to folder “F:\4testbackup”:

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

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

  • ROBOCOPY “source” “destination” .FileExtension /S /MINAGE:n

Example 1: Command to copy all JPG files created 180 days ago from folder “C:\4test” and its subfolders to folder “F:\4testbackup”:

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

Example 2: Command to copy all JPG files created 180 days ago from folder “C:\4test” and its subfolders to folder “F:\4testbackup”:

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

Example 3: A command to copy all JPG files created in the last 180 days from the folder “C:\4test” and its subfolders to the folder “F:\4testbackup”:

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

Example 4: A command to copy all JPG files created in the last 180 days from the folder “C:\4test” and its subfolders to the folder “F:\4testbackup”:

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

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

If you found this article useful, please support us by donating. Even $1 can make a big difference for us We continue to help others while keeping this site free:

Leave a Comment