Powershell to copy and sort files into dated folders and filetype subfolders Aug 26, 2019 • Joe The below Powershell script will copy files from one location to another, picking only the ones that were created within a specified date range and matching particular filetypes/extensions. Matching files are copied to dated folders with a custom description and further split by file extensions into subfolders. The steps it takes are listed below: Default values are set in the $defaultVals hashtable in the script Change the source and destination values to something appropriate! Ask for $daysOldest, the farthest (in whole days) you want to go back in time e.g. 5 Ask for $daysNewest, the closest (in whole days) you want to go back in time e.g. 2 Ask for $description, the custom description to tack onto the end of the dated folders. e.g. A Summer’s Day would give 2001-03-24 - A Summer's Day as the dated folder Ask for $include[], an array of allowed file extensions in the form include[0]: *.jpg, include[1]: *.txt etc. (you can leave this blank to include all files (*) by default) Ask for $source and $destination directories – you should change these defaults even if you don’t change any others Check that each file in the $source directory has an allowed file extension and was created within the date range specified Work out the new folder structures and create them if they don’t exist Check if the files has already been added to the destination Copy the files NOTE: Replace the source and destination paths in the $defaultVals hashtable! Dated_and_extension_file_sort.ps1: You can find the latest version of the script in the Dated and extension file sort repo on my GitHub. This was written to make transferring and organising photos a little easier, particularly after I found thousands of old photos in a giant mess when going through backups. The end result looks a little something like this: > Dated_and_extension_file_sort.ps1 daysOldest: 2 daysNewest: 1 description: Wedding source: <e.g. an SD card from a camera> destination: <e.g. holiday pics folder> include[0]: *.jpg include[1]: *.avi include[2]: *.mp4 include[3]: *.xcf include[4]: Updated 2019-08-20 to be more robust. Updated 2019-08-21 to remove config file. Updated 2019-08-21 to fix issue with -Include filter (use the arrays, Luke) and description. Updated 2019-08-26 to remove vestigial Get-ScriptDirectory() function, moved daterange and directory validation to parameters, added # of copied and skipped files processed to output, cleaned inappropriate quotation marks Blog Categories: Games (44) D&D (43) Lost Mines of Phandelver (10) Curse of Strahd (1) 3 Wizards 1 Cleric (4) HotDQ (2) Photos (4) Tech (2) Wildemount (8) EBAC (7) The Seven Oaks (4) Freehold (4) Space Engineers (1)