批量重命名使用文件夹名称的文件? [英] Batch Rename Files using Folder Name?

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

问题描述

我在找创建一个脚本,将它们在文件夹的名称后的文件夹中的所有图像重命名,这将被用于因为我用它来规范一次重命名多个文件夹值得图像我所有的漫画的命名方案。所以,我会说75 * .cbz是在一个目录生病解压缩,从包含包含构成每个漫画每个图像重命名图像文件夹的子文件夹内,然后我会说运行脚本。

I'm looking to create a script which will rename all images in a folder after the name of the folder they are in. This would be used to rename multiple folders worth of images at once since I'm using it to standardize the naming scheme of all my comics. So I would have say 75 *.cbz's ill unarchive in a directory, then I'd run said script from within a folder containing the sub folders which contain the images that make up each comic to rename every image.

该结构将是例如:

PageRenamer.bat

PageRenamer.bat

系列名称000(年)\\

Series Name 000 (Year)\

名称pg1.jpg,名称pg2.jpg ...名称pg24.jpg

Name pg1.jpg, Name pg2.jpg... Name pg24.jpg

系列名称001(年)\\

Series Name 001 (Year)\

系列名称001 000.jpg,系列名称001 001.JPG ...系列名称001 025.jpg

Series Name 001 000.jpg, Series Name 001 001.jpg... Series Name 001 025.jpg

等等...

最终的结果,我找的就是你运行该脚本后,每幅图像被命名为系列名称001(年)000.jpg - 系列名称001(年)025.jpg (页数/图像可能会有所不同),并在系列名称001(年)住\\ 夹。现在,这是所有希望我的漫画是单层档案。它会变得更好,如果有集成到每个子文件夹(漫画根)的根文件夹的子(漫画根)内移动的子文件夹中的任何图像的能力的一种方式。
例如:

The end result I'm looking for is that after you run the script every image is named Series Name 001 (Year) 000.jpg - Series Name 001 (Year) 025.jpg (number of pages/images may vary) and dwells in the Series Name 001 (Year)\ folder. Now this is all hoping my comics are single layer archives. It'd be even better if there was a way to integrate the ability to move any images in sub folders within each sub folder(comic root) to the root sub folder (comic root). Example:

PageRenamer.bat

PageRenamer.bat

系列名称000(年)\\

Series Name 000 (Year)\

系列名称000 \\

Series Name 000\

名称pg1.jpg,名称pg2.jpg ...名称pg24.jpg

Name pg1.jpg, Name pg2.jpg... Name pg24.jpg

系列名称001(年)\\

Series Name 001 (Year)\

系列名称001 \\

Series Name 001\

系列名称001 \\

Series Name 001\

系列名称001 000.jpg,系列名称001 001.JPG ...系列名称001 025.jpg

Series Name 001 000.jpg, Series Name 001 001.jpg... Series Name 001 025.jpg

等等...

改变以匹配实施例1(包括删除现在未使用的子文件夹)的格式。任何帮助是非常欢迎的,我会很乐意得到足够简单,做的第一件任务,因为大部分的漫画是一层的脚本。这将会是一个巨大的奖金,如果我不担心固定不属于的。

Changing it to match the format of example 1 (including deleting the now unused sub folders). Any help is very welcome I'll be happy to get a script simple enough to do the first task since most comics are one layer. It'd be a huge bonus if I wouldn't have to worry about fixing the ones that aren't.

推荐答案

我就扔批处理脚本在这里几行你指出正确的方向。你可以用这样的forloop启动,这将列出所有子目录中的文件夹的漫画:

I'll just throw a few lines of batch script in here to point you in the right direction. You can start with a forloop like this, which will list all of the subdirectories in your comic folder:

  for /d %%D in (*) do

然后在有第二forloop,采取在每个子目录中的所有.JPG的并重新命名:

Then have a second forloop in there, to take all the .jpg's in each subdirectory and rename them:

for %%f in (*.jpg) do (
       #here you will want to craft a string for the filename, using the subdirectory name (%D)
       ren "%%F" "your-crafted-string.jpg"
 )

您将需要跟踪一个变量来存储你命名处理的文件#:

You'll need to track a variable to store the # of files you've processed for naming:

 set /A num=0

您可以增加这个在内部循环运行的每个循环:

You can increment this each loop run in the inner loop:

 set /A num+=1

和重置为外循环(每个子目录)的每个增量:

And reset it for each increment of the outer loop (each subdirectory):

 set /A num=0

制作一个字符串最内层循环中的每个文件看起来像这样(未经):

Crafting a string inside the innermost loop for each file would look something like this (untested):

 ren "%%F" "!%%D%_%num%!.jpg"

您可以读取此为'重命名[文件]为[目录名] _ .JPG [NUM的价值]

You can read this as `rename [the file] as "[Directory name]_[value of num].jpg"

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

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