Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

zqbobs

macrumors regular
Original poster
I have thousands of scanned pre-digital photos with file attributes of:

Photo Date (YYYY-MM-DD at the front of the filename)
Index # (4-digit sequential numerical index to the archived photo file, at the end of the filename)

I can obviously sort the photos by date easily in a Finder window by sorting the filename, but I would also like to sort them by the index #. I know I could create a copy of all the files by moving the index # to the front of the filename and then sorting by filename, but is there another way that wouldn’t require changing the filename?

Maybe I could modify one of the unused Finder file attributes, in a way that would allow sorting? For example, is there a way to set the “Comments” attribute automatically, like from a Numbers spreadsheet? That should allow me to sort “Comment” as a surrogate for the index #.

If Shortcuts, Automator or Hazel are useful here, please give me a sample script if you can.

There may be a much simpler way to do this which I’m not seeing. Any ideas or tips are welcome!
 
I wrote a small C utility for dumping a list of folder names in a folder and creating symlinks because there was no way to do this that I could find from the terminal without hitting all kinds of problems.

You could modify my program to read the numerical code and sort the file names that way and print them to the terminal or whatever you want to do with the data.

Code:
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    struct dirent *de;

    char *path = "/Volumes/Tiles/\0"; // Path of folder to read
    char str[1000];
    
    DIR *dr = opendir(path);

    if (dr == NULL)
    {
        printf("Could not open current directory!\0");
        return 1;
    }

    while ((de = readdir(dr)) != NULL)
    {
        if(de->d_type == DT_DIR && de->d_name[0] != '.') // Excludes dot-folders
        {
            memset(str,0,1000);
            
// Build the string for display/symlink/whatever
            int strpos = snprintf(&str[0],strlen(path)+1,"%s", path);
            snprintf(&str[strpos],strlen(de->d_name)+1,"%s", de->d_name);
            printf("%s\n", str);
            
            int ret = symlink(str, de->d_name); // Create symlink
            
            if(ret != 0) // Check if something went wrong
            {
                printf("Error linking directory: %s",de->d_name);
                closedir(dr);
                return 2;
            }
        }
    }
    
    closedir(dr);
    
    return 0;
}
 
I wrote a small C utility for dumping a list of folder names in a folder and creating symlinks because there was no way to do this that I could find from the terminal without hitting all kinds of problems.

You could modify my program to read the numerical code and sort the file names that way and print them to the terminal or whatever you want to do with the data.

Code:
#include <stdio.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>

int main(void)
{
    struct dirent *de;

    char *path = "/Volumes/Tiles/\0"; // Path of folder to read
    char str[1000];
   
    DIR *dr = opendir(path);

    if (dr == NULL)
    {
        printf("Could not open current directory!\0");
        return 1;
    }

    while ((de = readdir(dr)) != NULL)
    {
        if(de->d_type == DT_DIR && de->d_name[0] != '.') // Excludes dot-folders
        {
            memset(str,0,1000);
           
// Build the string for display/symlink/whatever
            int strpos = snprintf(&str[0],strlen(path)+1,"%s", path);
            snprintf(&str[strpos],strlen(de->d_name)+1,"%s", de->d_name);
            printf("%s\n", str);
           
            int ret = symlink(str, de->d_name); // Create symlink
           
            if(ret != 0) // Check if something went wrong
            {
                printf("Error linking directory: %s",de->d_name);
                closedir(dr);
                return 2;
            }
        }
    }
   
    closedir(dr);
   
    return 0;
}

Thanks, but I don't do C. Need a higher level solution.
 
It's worth learning. It is a heck of a lot simpler. I spent 3 hours trying to do it with a zsh script only to find it is something you can't do without lots of headaches. Took me 15 mins to write the utility above AND it handles all the weird edge-cases.
 
If Shortcuts, Automator or Hazel are useful here, please give me a sample script if you can.

There may be a much simpler way to do this which I’m not seeing. Any ideas or tips are welcome!

So a sample filename might be "2006-06-16 Super Fun Day #1234.jpg"?

Are you trying to get a list of the sorted-by-index filenames in order, or are you trying to view the sorted result right in a Finder window?

Off the top of my head, I think Shortcuts or Automator might do it. I could give it a shot shortly.
 
There may be a much simpler way to do this which I’m not seeing. Any ideas or tips are welcome!
Might be useful to better understand why you want to sort by "index #". If the use case is basically a search or find, then something like Commander One might be helpful.
 
So a sample filename might be "2006-06-16 Super Fun Day #1234.jpg"?

Are you trying to get a list of the sorted-by-index filenames in order, or are you trying to view the sorted result right in a Finder window?

Off the top of my head, I think Shortcuts or Automator might do it. I could give it a shot shortly.
yes, that's a simplified example of the filenames. # is not actually used, but brackets [] and some text within are used, e.g. [Fam7_0345]. The character length (11) of the index is the same for all photos.
 
Might be useful to better understand why you want to sort by "index #". If the use case is basically a search or find, then something like Commander One might be helpful.
I want to sort by index to account for all photos, note ones missing, etc. Over the years, the files have gone through a lot of moving folder-to-folder, name changes etc, and I'm trying to consolidate all into one place with a consistent link (the index) back to the original scan archive. There are some 5500+ photos.

I'll look at Commander One - may be useful in general. I like dual-pane Finder alternatives like ForkLift.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.