Author Topic: Sorting by even/odd filename  (Read 298 times)

Offline randall_benton

  • Newcomer
  • *
  • Posts: 17
    • View Profile
Sorting by even/odd filename
« on: January 01, 2024, 05:23:03 PM »
I am cataloguing a coin collection, shooting obverse (heads) followed by reverse (tails). I want to be able to sort them by even/odd filenames so I can add keyword, 'heads' to all the odd numbered files, and keyword, 'tails' to all the even numbered files. I found a similar question answered in this forum, but the solution given does not give the results I expected. The results I get sorts all the filenames ending zero, followed by all the filenames ending 1, followed by all the filenames ending in 2, etc. Since I have hundreds of files, the sort shows me a few dozen 'tails' followed by a few dozen 'heads' then a few dozen 'tails', etc.  Is there a way to sort these files so that I see ALL the even numbered files, followed by ALL the odd numbered files?
Thank you very much for your help.

Offline RogerB

  • Newcomer
  • *
  • Posts: 36
    • View Profile
Re: Sorting by even/odd filename
« Reply #1 on: January 02, 2024, 12:29:33 AM »
If I've understood your naming convention correctly, your filenames all end with a number before the file extension, for example:

    image34.jpg
or
   image0745.jpg

Assuming that's correct then I would approach this with a regular expression search rather than sorting the images.  If you set up the Find window as shown in the attached image it will select all of the odd numbered files, and you can then use the Metadata Template to apply the keywords you want.  Once you have done that, invert the selection and you will have all of the even numbered files selected, and can then apply the keywords to those.

This assumes your filenames all end in jpg, but if they are something else (e.g. .CR3) then update the search term accordingly.  It also assumes that all of the files have the same extension, if they don't then the search expression can probably be modified to work, but you'll need to explain more about how the files are named.

In case the regular expression search term can't be read easily from the image it is
Code: [Select]
.+[13579]\.jpg$

I've tested this in a folder of about forty images and it works as I expect, but please test it yourself and make sure it's selecting the files you want before you apply the metadata template.  It's also sensible if you're modifying the metatdata of hundreds of files at once to make sure you have a backup of the files which you can restore if something goes wrong.

Offline randall_benton

  • Newcomer
  • *
  • Posts: 17
    • View Profile
Re: Sorting by even/odd filename
« Reply #2 on: January 02, 2024, 10:44:06 AM »
Thank you very much RogerB! All your assumptions were correct, and this solution worked perfectly. The bonus was that I learned a bit more about these functions within PM that I seldom use. Thanks again.