Timothy Goodman
Timothy Goodman

Reputation: 15

How do I Batch Rename Folders in OSX?

So I have been trying to rename about 5000 folders based on a CSV (Old name, Newname)

This is a one time operation, once hdkjsh2-2f8c-46b9-bbdb_doc is converted to 3 then it will not need to be touched again.

I have tried the solution here (Setting up an automator workflow with a command script) but found that it does not do a great deal when it comes to folder/directory names and all the guides/documentation is around file names and not folder. Any suggestions would be much appreciated

Example of CSV

Doc_Location,  New_ID
hdkjsh2-2f8c-46b9-bbdb_doc , 3

Upvotes: 1

Views: 2376

Answers (2)

Mark Setchell
Mark Setchell

Reputation: 207405

Please make a backup before trying the following.

Save the following script in your HOME directory as renamer:

#!/bin/bash

cat "file.csv" | while IFS=' ,' read dir new ; do
   if [ -d "$dir" ]; then
      echo Rename $dir as $new
      #mv "$dir" "$new"
   else
      echo "ERROR: Directory $dir not found - ignored"
   fi
done

Then start Terminal and make the script executable by running:

chmod +x $HOME/renamer

Then change directory to where your directories are that need renaming:

cd path/to/things/needing/renaming

Make sure you have your CSV, called file.csv saved in that directory, then run with:

$HOME/renamer

It doesn't actually do anything, it just tells you what it would do. If it looks correct, edit $HOME/renamer and remove the single # on the line that says:

#mv "$dir" "$new"

so that is looks like:

mv "$dir" "$new"

Then be doubly sure you have made a backup and run the script again:

$HOME/renamer

Upvotes: 1

Natsfan
Natsfan

Reputation: 4802

Go to the folder where the other folders you want to rename are located. Select all the folders you want to rename. Then click on the action icon at the top of finder window. This will open a window where one option is to rename x items. See image below.

enter image description here

When you select "Rename x items" you get a box like the one shown below where you can specify the new names.

enter image description here

Upvotes: 1

Related Questions