Folder creation by Filename beginning similarity

Hello Experts,

I would like to build a macro, but this seems to be over my head.

Goal: “ place all files with the identical first “x” characters to a new folder with that name.”

For Example I get hundreds of these audio files for DX,FX and MX generated by my audio software:

Soundmix_202511_DX51.L.wav

Soundmix_202511_DX51.C.wav

Soundmix_202511_DX51.R.wav

Soundmix_202511_DX51.Ls.wav

Soundmix_202511_DX51.Rs.wav

Soundmix_202511_DX51.LFE.wav

Soundmix_202511_MX51.L.wav

Soundmix_202511_MX51.C.wav

Soundmix_202511_MX51.R.wav

Soundmix_202511_MX51.Ls.wav

Soundmix_202511_MX51.Rs.wav

Soundmix_202511_MX51.LFE.wav

Soundmix_202511_FX51.L.wav

Soundmix_202511_FX51.C.wav

Soundmix_202511_FX51.R.wav

Soundmix_202511_FX51.Ls.wav

Soundmix_202511_FX51.Rs.wav

Soundmix_202511_FX51.LFE.wav

I want to select them all at once and have the macro automatically put them in three new correspondingly named folders:

Soundmix_202511_DX51

Soundmix_202511_MX51

Soundmix_202511_FX51

I found tthis macro by Dan Thomas https://forum.keyboardmaestro.com/t/create-folder-from-filename-move-file-to-new-folder/37482/4 but it seems to only make and name a folder for each file.

But maybe it can be tweaked to do what I’m trying?

I also thought of:

“If names are similar when trimmed 6 places from the end, then place files in new folder with that name”

Any help would be highly appreciated. Thanks..

I like these kinds of problems. I have a family event for the next hour, but I have enough time to ask you for some clarifications.

  1. What happens if the folder already exists? Do you want the macro to abort, or just add to the folder?
  2. Do you really need the files to be selected first, or is it okay if the macro just asks you for the folder name and the macro works just from the folder?
  3. Does it matter if the solution mostly uses macOS commands in an Execute Shell action instead of using mostly KM file-related actions?
  4. Can you guarantee that none of the files in that folder will be "in use/open" by the app?

If someone else gives you a solution before I return from my family event, that's okay with me.

  • What happens if the folder already exists? Do you want the macro to abort, or just add to the folder?

Abort I guess

  • Do you really need the files to be selected first, or is it okay if the macro just asks you for the folder name and the macro works just from the folder?

That would work too

  • Does it matter if the solution mostly uses macOS commands in an Execute Shell action instead of using mostly KM file-related actions?

I don’t think so. KM would be more understandable for me though:))

  • Can you guarantee that none of the files in that folder will be "in use/open" by the app?

No. But I just need to restart the App file (ProTools) and it asks to search for the files new location

Ok, I think it's working. I will upload it here shortly, in a minute. Here it is... (as I uploaded it, I realized it can even be shortened further, but it's good enough as it is.) Of course, give it a try, because maybe I missed the target in some way. Let me know if I misunderstood the requirement.

SoundMix Macro (v11.0.4)

SoundMix.kmmacros (4.8 KB)

It isn't a perfect example of well-written code, but if you like it, I can probably tweak it to make it a little better.

You may want to change the first action to start the window in a more appropriate default directory.

2 Likes

Hey Airy,

thank you very much. I’m impressed by how quickly and (apperently:) effortlessly you pulled that out of your sleeve. It works exactly as described…I’ll test it further in the studio tomorrow. However, the constant “soundmix” is variable in real life and still needs to be adjusted depending on the case. But thats doable:-)) It’s definitely already a big help. Thanks!!!

1 Like

It was my pleasure. I enjoy challenges like this. Perhaps you are able to enhance this macro to suit your needs better, but if not, let me know. My code could be improved a bit, but it does the job, though I may not have met all your requirements perfectly.

1 Like