如何在OSX中批量重命名文件夹? [英] How do I Batch Rename Folders in OSX?

查看:99
本文介绍了如何在OSX中批量重命名文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直试图基于CSV(旧名称,新名称)重命名大约5000个文件夹

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

这是一次操作,一旦将hdkjsh2-2f8c-46b9-bbdb_doc转换为3,就无需再次触摸它.

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

CSV示例

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

推荐答案

请先进行备份,然后再尝试以下操作.

在您的HOME目录中将以下脚本另存为renamer:

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

然后启动Terminal并通过运行以下命令使脚本可执行:

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

确保将名为file.csv的CSV保存在该目录中,然后运行:

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

$HOME/renamer

它实际上什么也没做,只是告诉您它将做什么.如果看起来正确,请编辑$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"

所以看起来像这样:

mv "$dir" "$new"

然后请确保已备份并再次运行脚本:

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

$HOME/renamer

这篇关于如何在OSX中批量重命名文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆