How to Batch Copy or Move files based on Extension and Date.
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.
This tutorial contains instructions on how you can copy or move, a large set of files to another location, by using ROBOCOPY.
- Source: Robocopy Complete Reference
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.
We're hiring
We're looking for part-time or full-time technical writers to join our team! It's about a remote position that qualified tech writers from anywhere in the world can apply. Click here for more details.
- How to Disable or Remove BitLocker from Windows RE. - April 24, 2024
- FIX: Error 0x8007025d in Windows 10 Update. - April 22, 2024
- How to Disable Device Encryption in Windows 11/10. - April 17, 2024
Scott Whiteman
April 14, 2021 @ 9:39 pm
This is a very helpful suggestion. Do you have a tip on moving the files within the subfolders, but not recreating the subfolders, in the new location?
lakonst
April 15, 2021 @ 9:13 am
I think is not needed an extra step for that. If ROBOCOPY finds the same folder in the destination it will not re-create it.
Sarah Montari
December 5, 2021 @ 3:00 pm
tools like Duplicati or Gs Richcopy 360 can do it easily , check the trial versions first