How to Replace Text in a Folder Name in the Finder

Hi, I searched, but couldn't find any Topics describing exactly what I want to do. I want to search my "Downloads" folder for all the folders within that contain the characters "123 wxyz" in their folder name and simply remove all those characters, so replace with nothing I guess. Is there a Macro anybody can point me to? Or do you know how I would do this? Thank you so much!

Just folders? Do you also want to look inside those folders to rename any sub-folders that also have names containing that string?

1 Like

Correct, just remove those characters from a bunch of folders within my Downloads folder, no subfolders, no files, just those main root folders in Downloads. Thanks!

It can be done more concisely, but this verbose macro should be easy for you to adjust/repurpose as needed. And it's safety-first in that it'll only rename items that are both a folder and whose name contains the string you are searching for.

Rename Downloads.kmmacros (3.9 KB)

Image

1 Like

That worked perfectly! Thank you so much!

Follow-up question:
I need to do this with several different character strings. Which parts do I duplicate? Or can I dupe the macro itself, rename the macro, set a different character string & then put all those macros inside of a "container" which then they could all be activated with a single Trigger? Thanks!

You can do it in different ways, but the most efficient would be to have one macro like the above but with multiple "if a then change to x, else if b then change to y, else if c then change to z...".

But, and it's a very big but...

The more of these you are doing, the more chance there is of the macro failing because of a name clash -- eg if you're deleting "123" and "456", it'll fail if you've downloaded Folder 123 stuff and Folder 456 stuff. It feels like this is part of a bigger workflow (I can't think of a reason to rename downloads and then leave them in the Downloads folder doing nothing), and how you deal with potential name clashes will depend on what else you are doing. So maybe describe what you are trying to achieve?

1 Like

Gotcha. I think I will make separate Macros, I need accuracy over function. Thanks again! You rock!