Sort files into folders by date created
apple Verified ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
It seems like this might be possible but I haven't found exactly what I'm looking for online... I have a ton of pictures and videos that I'd like to sort into folders based on the date the pictures or videos were taken. Can I automate the whole process of creating the folders named by date and then moving the files into the correct folder? I just discovered automator today and have no experience with apple script so I need specific directions. :)
15 replies
Sign in or join Beachball Help to reply.
- 0
Camelot ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
It is entirely possible to do, but there are a lot of details missing in your post that are required before a solution can be suggested.
For example, let's start with which date? Are you talking the date the picture was actually taken (which requires reading the metadata stored within the image file itself), or is the 'creation date' or 'modification date' of the file sufficient?
Secondly, what about granularity? Do you want to group pictures by each day? or all pictures from a specific month/year?
Let's start with that.
- 0
VikingOSX ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I have a working Automator application that takes the input folder containing the image and video files that you want to process and creates a set of all files matching those extensions. Based on that data, it then checks the file creation date of each file, and if the date named folder does not exist, creates a new folder using the yyyy-mm-dd date format, and copies the respective file into it. Here is an example output when Automator completes:
I simply duplicated my Pictures folder to the Desktop, and let it rip. Two Automator actions:
- Ask for Finder Items
- Run Shell Script
I am using Ruby for the processing, and I believe the elapsed time for the file count suggests speed. Tested on macOS High Sierra with the System Ruby v2.3.7.p456. Testing performed on a 2011 Mac mini with 128GB SSD and 16GB RAM.
If you want the Ruby code and instructions to create the Automator application, let me know and I will post them here.
Some assumptions made:
- Date-stamped folders created in the same folder as the processed files
- All files that have the same creation date are placed in the appropriate yyyy-mm-dd folder
- The use of yyyy-mm-dd formatting for the folders as they sort well without white-space.
- That you would want process completion notification and counts.
A file date-stamped in the Finder will use the EXIF DateTimeOriginal field if it exists in the image, otherwise a UNIX creation date will be associated with the file.
- 0
zarin123 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thanks for your response!
If it can be done using metadata to get the date the picture/video was actually taken that would be great as I do have a large amount downloaded from the cloud so the created date is off.
Also, I’d like to sort by date, not just moth.
- 0
zarin123 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
VikingOSC, this sounds like exactly what I’m looking for! Please let me know how to do it. Thanks!!
- 0
VikingOSX ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Currently, the Ruby application gets the creation date from the individual image. In general, Ruby does not include a standard library within it to access EXIF data in an image, and I do not post code that requires the extra confusion of adding these third-party modules. That said, there is a macOS native way to get EXIF data from an image that I am researching right now.
I can post the Ruby code and Automator steps first thing in the morning (Jan 11).
- 0
VikingOSX ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
What additional image and video extensions do you need that are not shown in this initial set? What is not needed?
I need a few minutes yet this morning to test on Mojave 10.14.2, before posting. I found some code late last night that allowed me to pluck the DateTimeOriginal field from an image's EXIF data, but it is in a language that requires a compiler to use, and I would need additional time to translate it, and avoid the compiler necessity. This morning's post will not integrate the EXIF capability.
The current Ruby code only takes the items on the first level inside the prompted folder.
- 0
rccharles ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
You can get more than you will ever need 😎 with the terminal command exiftool. You would get the create date by:
mac $ exiftool -createdate dscn0851v-p.jpg Create Date : 2015:10:17 14:07:33https://www.sno.phy.queensu.ca/~phil/exiftool/
Great command. Tedious to use. Best to google what you want to do.
R
- 0
zarin123 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
I have .mpg, .mts, .mp4, avi, .mov, .psd, .jpg, .nef
- 0
VikingOSX ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
The Ruby script that I am about to post will check for the availability of exiftool and if installed, it will make two attempts using different EXIF/IPTC tags to get the creation date. If it cannot, then it will use the System time on the file instead. Added this capability while waiting for the OP to respond with extensions.
- 0
VikingOSX ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Had some issues with the hosting software that won't let me post the solution here. Getting a Google Drive shared folder and documentation ready. Will post the link here in a few minutes. I highly recommend having BBEdit or another language-aware programmer's editor installed. The Ruby script is zipped, and once unzipped, you need to open it in BBEdit so the formatting is preserved. Then you can safely copy/paste into the Automator Run Shell Script as I just did as part of testing.
Ruby solution now checks for the presence of Phil Harvey's exiftool, and will attempt to extract EXIF/IPTC creation date information with that tool. If the tool is not installed, or cannot extract creation date information, then the System creation date for the file will be returned as 'yyyy-mm-dd' and the folder created, if it does not already exist.
I also updated the code to build a set of all existing folders that match the 'yyyy-mm-dd' naming format, and only create new folders that are not in this set. This means that when you add files to this containing folder, and re-run the script, it may only need move the file into an existing 'yyyy-mm-dd' folder. Performance gain.
- 0
VikingOSX ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
You can get the Ruby Script, a PDF of the source code, and an installation README PDF at this Google Drive folder.
Without exiftool:
With exiftool:
- 0
zarin123 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Thanks! I got it all set up and works great except for with the set of photos I have where the "date created" and the Exif "date time original" are different. (Example shown in image below.) I followed your instructions to get exiftool, and when it didn't sort those images, I tried the installation again in case I messed something up. It said exiftool 11.11 is already installed and up-to-date. Could I have done something else wrong?
- 0
VikingOSX ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
Earlier this morning, I updated the Ruby Script to v1.5 on the Google Drive location. Improved logic, and shaved about 13% off of the previous runtime for same quantum of files.
You don't need to run exiftool, unless you want too. The Ruby script will detect if it is installed, and will run it in the background — looking first for the tag 'DateTimeOriginal', and if not found, then the tag 'FileModifyDate' in the given image file. Whichever it finds, it will return a formatted date string as 'yyyy-mm-dd' that will be used for the folder name. If exiftool is not installed, or for some reason, it could not retrieve a date string value for either EXIF tag name, then it will simply get the System creation date from the file.
In the preceding, and in those cases where the given image does not have the tag 'DateTimeOriginal', the poorly named 'FileModifyDate' appears to be the actual creation date. Very misleading.
I have some image files, including raw file formats downloaded from the Internet, where the internal creation date, is different from the Finder Get Info created date. Expect that.
When you run the Automator application, what is the final dialog report on number of images, folders, and elapsed time?
- 0
zarin123 ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
This is from when I tested last night
- 0
VikingOSX ·
Imported from the Apple Support Forums via the Wayback Machine 🔗
How does the above time compare when using the v1.5 Ruby script that I posted this morning?