[Solved] Sort files into folders based on first two digits of filename?

NicholasGFX Asks: Sort files into folders based on first two digits of filename?
I constantly get hundreds of .pdf files I would like sorted into folders based on the filename.

The filenames are made up of a couple elements, although only the first string of letters and the first two digits are relevant. The letters represent the customer code and the digits represent the year.

Here’s two examples:

  • TX204190_100_GR.pdf. TX is the customer code and 20 represents 2020.
  • SFLYMK220921_CR2050_BLKHTH.pdf. SFLYMK is the customer code and 22 represents 2022.

The PDFs start off as direct siblings to the year folders. I need these PDFs to go inside the correct year folder and then the correct customer folder. So for example, TX204190_100_GR.pdf would need to go inside 2020 and then go inside the TX folder. The folders will all already exist.

Before Sorting Example

After Sorting Example

I’m struggling to find a way to select only the customer code (which can be anywhere from 2 to 8 characters) and the following two digits with automator so that I can properly move the files. I’d assume it requires some kind of regex solution, but I don’t know where to even begin or even if that’s possible using only Automator. Any advice or help with this is greatly appreciated.

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.