Python Scripting [7A]: Change File Modification Time on Map Images

This scripting project is a part of the NZ Rail Maps project. The aim is to change file modification times for a group of maps so that they follow a certain sequence when imported into Google Photos.
In the NZ Rail Maps project, maps published at what is defined as the “Basic” level are produced in two formats. These are “Aerial Maps” with the filename being in the format:
  • First character is the capital letter “A”
  • Next three characters are the numerical digits “000” to “999”
  • Followed by the suffix “.jpg”

This means the filenames are a sequence and all operating systems will sort them in sequence alphabetically.

The other format is “Diagram Maps” which is the same as above except the first character is the letter “D”.

When working with programs that recognise alphabetical sorting of file names there is generally no problem. However, Google Photos only sorts according to age which is assumed to be file modification time. 
The purpose of the script is to achieve these objectives which are both achievable simultaneously:
  • Ensure that all A series maps are given a file modification time that follows the same sequence as their filename, and then follow the same process for the D series maps
  • Ensure that for each numerical sequence number, the A series map is directly succeeded by the D series map.

Example: A001.jpg, D001.jpg, A002.jpg, D002.jpg will be the strict order by file modification time after running the script.

This means where both types of map are placed in the same disk folder, Google Photos will interleave them when imported. The user can also use the alphanumerical sorting order in the file dialog box to only import one series instead of both at the same time, if the Google Photo album should only contain one type of map instead of both.
This means that in addition to discrete “Aerial Maps” and “Diagram Maps” photo albums there can also be a “Combined Maps” photo album easily.
There can be variations of the filename format such as Axxx-2015-Old.jpg so basically the steps required are extract the first letter as a letter and then the next three characters as digits and then save the rest of the filename after that but getting the exact sort order is a little tricky as it does require taking into account more than just the first four characters of the filename. All we guarantee is that the first four characters are Axxx or Dxxx where xxx is a numerical digit sequence from 000 to 999.

by

Tags: