1

I have a lot of folders named the same way with the year at the start and I would like to somehow move the year to the end of the folder name

For example, current folder name:

(1999) Robert Wyatt - EPs

and I would like it to be:

Robert Wyatt - EPs (1999)

When searching I find a lot of answering with the rename command but it isn't recognised on Mac

What tools and techniques can accomplish this?

3 Answers 3

3

Short shell script

Run

for s in *; do
    t=$(sed -E 's/^(\([[:digit:]]{4}\)) (.*)/\2 \1/' <<< $s)
    [[ "$s" != "$t" ]] && mv "$s" "$t"
done

in the directory containing the directories to be renamed.

Install rename

You can install rename via Homebrew with brew install rename.

Use a simple rename.pl

Create a little perl script yourself:

#!/usr/bin/perl
# Usage: rename perlexpr [files]

($op = shift) || die "Usage: rename perlexpr [filenames]\n";

chomp(@ARGV = <STDIN>) unless @ARGV;

for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}
2
  • Thank you! I appreciate the info re: Homebrew, it helps make sense of a lot of other stuff. Pearl scrip is way over my head though, but thanks for believing in me 😂
    – johndoe
    May 6 at 9:10
  • @johndoe You just need to save it as a text file named rename, run chmod +x rename and then execute it :-)
    – nohillside
    May 6 at 9:20
0

I am sure you could do what you want with a script in Terminal, but much easier to use A Better Finder Rename.

This apps as a wide range to rename tricks, but something like this would do what you want:

ABFR

Note the app is $25, but you can try it first. I am a happy user, nothing to do with the developer.

2
  • This application has been awesome for a long time. Highly endorsed for this task
    – bmike
    May 6 at 2:53
  • this looks perfect, thanks so much! I had tried 'Renamer' and 'NameChanger' but neither had the options I needed. Downloading now, thanks again
    – johndoe
    May 6 at 9:05
0

Paste this following AppleScript code into a new Script Editor.app document. Running the code in Script Editor will take all of the currently selected folders in the frontmost Finder window and re-name the selected folders by removing the date and parentheses from the beginning to the end of the folder name.

NOTE: If any of the selected folders' names in Finder don't start with a "(", or any of the selected items is not a folder... then the script won't rename that item.

tell application "Finder" to set theFolders to selection as alias list

tell application "System Events"
    repeat with i in theFolders
        if name of i starts with "(" then if kind of i = "Folder" then
            set originalName to name of i
            tell me to set newName to (characters 8 thru -1 of originalName) ¬
                & space & characters 1 thru 6 of originalName as string
            set name of i to newName
        end if
    end repeat
end tell

After testing this code a few times on some currently selected folders in the frontmost Finder window, and you are happy with the results... You can create a new Automator Quick Action and add a Run AppleScript command and insert the above code to it. Then save your new Automator Quick Action.

enter image description here

After you save your new Automator Quick Action, it will be available to use in Finder when you right click on the selected folders, in the Quick Actions menu. You will also be able to assign a keyboard shortcut in System Preferences to run the Quick Action on selected folders in Finder.

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .