Complex Batch File Renaming With Shortcuts and Regular Expressions

If the Finder's batch rename tool can't do what you want, you can always create your own complex file renaming scripts using the Shortcuts app and regular expressions.

Comments: 13 Responses to “Complex Batch File Renaming With Shortcuts and Regular Expressions”

    Jose Vasquez
    1 year ago

    I wonder if this Shortcut could be used to batch create PDFs from text files by "renaming" the extension to "pdf." I figured creating PDFs is a good way to backup documents created in Pages, Word and Text Edit.

    Thanks,

    Jose Vasquez

    1 year ago

    Jose: You can't create PDFs by just renaming document files. You have to open them up in the app you used to create them and export PDF files. PDF files can't be edited, really, so if your goal is to back up your files, just create copies of them. Or, just use Time Machine to back everything up (I assume you already are, right???)

    Jules
    11 months ago

    Hi Gary, this video shows how to switch existing words of a file name around, but is there a way to shorten/delete existing words? For example, rename the files to only the first word (e.g. the existing file “Alpha Beta Gamma” would become just “Alpha”). I have many files with long names that I want to shorten. Also, does this video lesson work for iPhone? I tried using your exact shortcut but my phone thinks I have a file literally named “^(\w*)\s(w*)\s(w*)$” and want to change it “$3 $2 $1”

    11 months ago

    Jules: Yes. You can do that. So instead of $3 $2 $1 you would just want to use $1 as the result. It should work on the iPhone too, yes.

    Jules
    11 months ago

    Thanks Gary. My bad, yes, it does work on iPhone (I had copied the expression incorrectly). Using $1 as the result works too, thanks for the tip.

    Is there an expression that can replace every word/character? (My files have more than three words). Using your shortcut, I tried changing ^(\w*)\s(\w*)\s(\w*)$ to the variable “text” (resulting from “get text”) hoping that $1 would replace all of the text to just the first word but it didn’t work.

    11 months ago

    Jules: You can do almost anything with regular expressions. That's a big topic. From your description I can't tell what you want though. Try searching online for regex or regular expressions to learn more.

    Jules
    11 months ago

    Gary, thanks for pointing to me regex (I didn’t know about it). I had a lot to learn and understand, but was able to accomplish my task. Thank you!

    Guillaume
    11 months ago

    Hi Gary, Do you have a simple shortcut for batch renaming files in the iOS Files app? Like adding text before, after or replace. The rename tool on the mac is not available on iOS. Thanks

    11 months ago

    Guillaume: Can you just do it on your Mac then? If the files are in iCloud Drive, which is usually the case for the iPhone, then just use the batch rename tool on your Mac to rename them. If not, doing it with Shortcuts isn't ideal but could work. It is just a matter of learning to use that action.

    alexander
    10 months ago

    Hi Gary, thx u for tutorial - trying to batch rename files (pdf) receipts based on contents date, name, product, currency amount, using shortcuts Quick Look, tried Automator with script -to difficult.

    10 months ago

    Alexander: Not sure what to suggest then. Difficult tasks require some amount of work. What's your reason for needing to rename the files when you can search for the contents inside the files with Spotlight?

    Agha
    7 months ago

    Hi Gary,

    Could you make a video or share a shortcut similar to the Automator's Quick Action “Rename Finder Items”? I've been using it for decades and now I want to convert it to Shortcuts, but can't export it there. In Automator's Quick Action “Rename Finder Items” user can choose how to change file names by choosing menu, and that's very useful.

    Thank you!

    7 months ago

    Agha: What is it you are trying to do? Can it be done with the regular Finder rename? If not, what is it you need?

Comments Closed.