How do I Batch Rename Folders in OSX?

一个人想着一个人 提交于 2019-12-11 09:12:35

问题


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

回答1:


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



回答2:


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.

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



来源:https://stackoverflow.com/questions/52057980/how-do-i-batch-rename-folders-in-osx

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!