重命名Jpegs的大文件夹 [英] Rename large folder of Jpegs

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

问题描述

我有一个很大的jpeg文件夹,我想依次将其重命名为image01.jpg,image02.jpg ... image533jpg等.

I have a large folder of jpegs, which I would like to rename sequentially to image01.jpg, image02.jpg...image533jpg etc.

我尝试使用以下

find ‘/myImages/‘ -maxdepth 1 -name ‘*.jpg’ | sort -n | awk 'BEGIN{ x=1 }{printf "mv \"%s\" \"/myImages/image%04d.jpg\"\n", $0, x++ }' | bash

我从这里得到的

:但是,这只是返回

>

然后什么也没有发生,任何建议都会很棒.

And then nothing happens, any suggestions would be great.

推荐答案

最简单的方法是使用rename,您可以使用 homebrew 使用以下命令安装它:

The easiest way to do that is with rename which you can install with homebrew using:

brew install rename

然后,您可以进入包含图像的目录并运行:

Then, you can go into your directory containing the images and run:

rename --dry-run -X -e '$_ = "$N"' *jpg

示例输出

'a.jpg' would be renamed to '1.jpg'
'article.jpg' would be renamed to '2.jpg'
'blob-0.jpg' would be renamed to '3.jpg'
'blob-1.jpg' would be renamed to '4.jpg'
'blob-2.jpg' would be renamed to '5.jpg'
'blob-3.jpg' would be renamed to '6.jpg'

如果看起来正确,则可以再次运行它而无需--dry-run实际执行操作,而不仅仅是告诉您它将执行的操作.

If that looks correct, you can run it again without the --dry-run to actually do it, rather than just telling you what it will do.

如果您想将姓名填充零,最简单的方法是让rename像这样自动计算所需的填充量:

If you want your names zero-padded, the easiest is to let rename work out how much padding you need automatically like this:

rename --dry-run -X -N ...01 -e '$_ = "$N"' *jpg


使用rename的好处是:


The benefits of using rename are that:

  • 它简单而强大
  • 它将在覆盖任何文件之前警告您
  • 它可以进行空运行并告诉您会发生什么,而无需实际执行任何操作

如果要解释命令'$_ = "$N"',请继续阅读...

If you want an explanation of the command '$_ = "$N"' then read on...

rename命令实际上是一个Perl脚本,因此我上面提到的部分只是一个用单引号引起来的Perl脚本. $N只是一个Perl变量,它扩展为一个顺序增加的数字.在执行您的小型Perl脚本之前,Perl特殊变量$_会用当前文件的名称填充,并且至关重要的是,您应该将其设置为您想要将该输入文件重命名为的名称.

The rename command is actually a Perl script, so the part I mention above is just a Perl script enclosed in single quotes. The $N is just a Perl variable that expands to be a sequentially increasing number. The Perl special variable $_ is filled with the name of the current file before your little Perl script is executed, and crucially, you are expected to set it to the name you want that input file renamed as.

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

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