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: 11 Responses to “Complex Batch File Renaming With Shortcuts and Regular Expressions”

    Jose Vasquez
    9 months 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

    9 months 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
    4 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”

    4 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
    4 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.

    4 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
    4 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
    3 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

    3 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
    2 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.

    2 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?

Leave a New Comment Related to "Complex Batch File Renaming With Shortcuts and Regular Expressions"

:
:
:
0/500 (500 character limit -- please state your comment succinctly and do not try to get around this limit by posting two comments)