Move photos to dated folders based on the date from the file name

Motivation

I have a Nexus phone, and I take a lot of pictures with it. I enabled Google Drive synchronization, so all my pictures and movies are saved to the Google servers once I get close to a Wi-Fi hotspot.

I really enjoy the functionality offered by Google Photos, but I am also old-fashioned: I like to have my photos on a hard drive that I can take with me to a desert island, if the time comes. To achieve this, I back up the photos from my phone on a regular random basis. I use Android File Transfer on Mac to copy the files from the phone using a USB cable. After such a backup, I will end up with a single folder with a huge amount of pictures in it.

I like to keep my photos organized in folders with names containing the date the pictures were taken. In order to achieve this, I created this simple task.

Implementation

The intention behind this task was to write it quickly and to make it run quickly. So it operates only on the filename. this is perfect for the cases when the file contains a number sequence encoding either the date, or the date and the time the picture was taken.

In a contrary case, this task will not work as expected. There is another similar task which will use the EXIF data from the file in order to achieve the same result.

Details

The task performs the following:

  •  Scans the source folder recursively, collecting all the recognized image and movie files
  • Extracts the date the picture was taken from the filename
  • For each day that has at least one picture, it creates a folder (the date format for the new folder can be set by the user). An optional prefix also can be added.
  • Each file will be moved (or copied, based on the user’s choice) into the corresponding new folder.