BBedit’s shell worksheet can be a really handy tool for batch renaming files. I was inspired to give it a shot after seeing a script that handed off a directory listing for editing. Here’s a really trivial example. Let’s say I have a directory containing the following files (and I’ve
cd‘d to it in the worksheet):
foo1.txt foo2.txt foo3.txt
And let’s say those files are actually Markdown, so I want to change the extension to
ls and execute it with Control-Return to get the listing of those files in your worksheet window. The result looks like the example above.
Next, highlight the listing, and bring up the “Find” dialogue. Make sure that “Grep” and “Selected text only” are selected.
Enter the pattern
(.*?)(\.txt), meaning a lazy search of any characters up to a literal
.txt, broken into two tokens. The first token is the file name, the second token is the extension. You want to replace that with
mv \1\2 \1.md;. The result will look like this:
mv foo1.txt foo1.md; mv foo2.txt foo2.md; mv foo3.txt foo3.md;
Select those lines and execute them using Control-Return. If you do another
ls, you’ll see your files have been renamed.
This example is really simple, just to get you thinking about the kind of file renaming you can do. Remember that a shell worksheet in BBEdit is a regular editing window. Any snippets, scripts, or text factory you have set up are available to you.