Patrick Desjardins Blog
Patrick Desjardins picture from a conference

How to copy files by name pattern and date under Windows with Robocopy

Posted on: 2015-10-28

This is not a post about Windows 10, but a post about how to copy a lot of files inside a folder that contains sub-folders. So far, this can be done by using Windows Explorer or the command line copy/xcopy but being able to select specific extension to copy, and a specific file prefix, and for a maximum date can be more challenging.

This is where RoboCopy shines! This tool is available if you have Windows Vista, Windows 7, Windows 8 and Windows 10. It's free. It's the next generation of xcopy -- more features. You can find some example directly on Microsoft Technet website.

The example that was concerning me was that I wanted to copy all .jpg file that start with an underscore, and all .NEF file to a backup drive. I also wanted only pictures after a specific date.

 ROBOCOPY C:\\source F:\\destination_*.jpg *.NEF /E /MAXAGE:20150806 

The first string is the name of the command. You should have this tool available if you open a Windows command prompt. To see if you do, just type Robocopy /?. This will give you the command line help for Robocopy if this one is installed. The first parameter is the source folder, the second the destination. Both of these parameter can only be folder. If you need to copy one specific file, you will need to use options. Options come after the source and destination folder in any order. In the example, I specify that I want all jpg extension file that start with an underscore. The stars is a wildcard for any characters. In the example, I want all NEF file, so I also specify every .NEF file (no prefix specified). The slash E (/E) means to go recursive. This take more time but is required if you have folders inside folders. The last option is /MAXAGE which take a date in year-month-day format.

The last step is to hit enter and you will see file being copied. If by misfortune your destination folder does not have enough space, Robocopy will pause and retry every 30 seconds. This let you clean up the destination drive for more space without having to restart the whole process. As you can see, this is a simple, free and powerful tool already installed on your Windows' machine that can help you