【问题标题】:Rename every other file重命名所有其他文件
【发布时间】:2013-06-28 11:21:28
【问题描述】:

我有很多文件想要重命名(手动操作太多),通常我会使用 Automator 但问题是,我需要将所有其他文件与之前的文件调用相同,但使用2 而不是1

这是我目前的文件

xxx - 401a - yyy.zzz
xxx - 401b - yyy.zzz
xxx - 402a - yyy.zzz
xxx - 402b - yyy.zzz
xxx - 403a - yyy.zzz

等等,但我想将它们重命名为类似

xxx - 401-pt1.zzz
xxx - 401-pt2.zzz
xxx - 402-pt1.zzz
xxx - 402-pt2.zzz
xxx - 403-pt1.zzz

无论如何要用自动机做到这一点?问是因为我真的很少使用 Automator,这意味着我不是你所说的专家。

编辑:这就是我想要实现的目标:http://wiki.plexapp.com/index.php/Media_Naming_and_Organization_Guide#Stacked_Episodes

【问题讨论】:

    标签: automator


    【解决方案1】:

    如果您对该工具一无所知,那么您不会介意使用其他工具吗?一个简单的shell命令怎么样?

    这是 Bash 中相同的操作,它提高了通用性。您可能不关心前两个,因为它已经硬编码了 yyy 和 zzz,但我这样做是为了向您展示 the sed command 以了解第三个。

    for file in * ; do mv "$file" "$(echo $file | sed 's/a - yyy/-pt1/g')"; mv "$file" "$(echo $file | sed 's/b - yyy/-pt2/g')"; done
    
    for file in * ; do mv "$file" "$(echo $file | sed 's/a - .*.zzz/-pt1.zzz/g')"; mv "$file" "$(echo $file | sed 's/b - .*.zzz/-pt2.zzz/g')"; done
    
    for file in * ; do mv "$file" "$(echo $file | sed -r 's/a - .*.([a-z]{3})/-pt1.\1/')"; mv "$file" "$(echo $file | sed -r 's/b - .*.([a-z]{3})/-pt2.\1/')"; done
    

    当然,其他命令必须有许多其他方式。 你会得到不重要的错误,因为 mv 在整个批次中执行了两次。

    【讨论】:

    • 看起来@Sébastien Dawans 为他提出的解决方案付出了相当大的努力,我计划学习和学习,但首先,我想警告你这句话:> 你会得到不重要的错误,因为 mv 在整个批次中执行了两次。我不认为忽略错误是明智的——甚至在一般编程时忽略警告。关于如何理解 bash shell 脚本,我会尽快回复您。
    • 嗨,感谢我提到“错误”的评论,这是因为 mv 在文件列表的输出中连续两次完成。在第二次迭代中,之前移动的文件不再存在。当然有一种更清洁的方法。
    • 嗯,似乎不起作用...每次我尝试都会得到这个sed: illegal option -- rusage: sed script [-Ealn] [-i extension] [file ...] sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]mv: rename Adventure Time - 213-pt2 - Mortal Recoil {C_P} (720p).mkv to : No such file or directory
    猜你喜欢
    • 2014-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-03
    • 2015-10-20
    • 2013-04-05
    • 1970-01-01
    相关资源
    最近更新 更多