Sort by end of a file name

Hi all,
I have a question. I have a folder of files (FLAC files). At the end of the file name I have the record company info number. Is there a way in finder (or on terminal) to sort based on the end of the file name?

I.e. “ file name Twit Records - 001.flac”

What I am trying to accomplish is to figure out if I am missing any albums based on “Twit Records - ###“

Any ideas?

I believe you would just search this way.

*Twit Records

The * is used as a wildcard in Windows not sure if that also works in Finder.

Thanks. I am able to search out the files I want. I was just hoping to be able to sort them numerically by the end of the filename.

As long as all the files have the same format up to the point where they differ they should sort alphabetically or numerically by any sort function again I’m going by Windows as I don’t have anything else in front of me.

I think you would have to have each number at the beginning of each name, and then just sort by name.

if you have files say

file name Twit Records - 001.flac
file name Twit Records - 002.flac
file name Twit Records - 003.flac

As long as everything before 001 and 002 and 003 is exactly the same it should sort correctly because it will go down the file name until it finds something that differs to know how to sort it.

I use NameMangler to bulk rename files with the power of regular expressions. If you have SetApp †, there’s Renamer included with that subscription. Using either, you could quickly move the number to the front in bulk, then sort by name.

† (I used my referral link.)

1 Like

In terminal use the ls command to list all the files of interest and redirect it to a text file:
ls *Foofile* >filelist.txt

Now you have a text file, you can use your favourite text editor to massage it how you like with search and replace or macros or whatever it takes. Maybe you want to insert some commas and make it a CSV file.

Copy and paste the text into a spreadsheet, especially if it’s CSV, and you should be able to do various sorting as needed.

Alternatively, on the command line use the stream editor to remove or replace bits you don’t need:

ls *MyFiles* | sed “s/^.*-//” >filelist.txt

1 Like