.bat批处理重命名为fname中的递增数字 [英] .bat for batch rename to increment numbers in fname

查看:180
本文介绍了.bat批处理重命名为fname中的递增数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的.cbr文件夹,我正在按发行号重命名它们以正确排序.我需要在ren行中包含哪些内容,以使每个文件通过Windows命令提示符递增文件名中的数字?我会经常这样做,所以我将其设为.bat文件.

I have a large folder of .cbr's, and I'm renaming them by issue number to correctly order them. What do I need to include in the ren line to have each file increment the number in the file name via windows command prompt? I'll be doing this frequently so I'll make this a .bat file.

例如,其中n =初始编号,m =最终编号:n.cbr,(n + 1).cbr,...,(m-1).cbr,m.cbr

For example, where n = initial number and m = final number: n.cbr, (n+1).cbr, ..., (m-1).cbr, m.cbr

.bat至今:

ren *.cbz *.cbr
ren *.cbr <increment numbers n through m>.cbr

或者,如何修剪每个文件名,以使扩展名前只剩下数字? (从issue1.cbr到1.cbr)通过.bat还是脚本宿主文件?

Alternatively, how do I trim each file name so that only the numbers are left before the extension? (from issue1.cbr to 1.cbr) via either a .bat or script host file?

推荐答案

尝试此批处理脚本.

@echo off
setlocal enabledelayedexpansion
set /a count=0
for /f "tokens=*" %%a in ('dir /b /od *.cbr') do (
 echo ren "%%a" !count!.cbr
 set /a count+=1
)

它使用增量计数器重命名所有文件.文件的顺序由DIR命令的/OD选项保留,该选项按修改后的时间戳对文件列表进行排序.

It renames all the files with a incremental counter. The order of the files is preserved with the /OD option of the DIR command, that sorts the files list by its modified timestamp.

经过仔细测试,删除ECHO命令.

After careful testing, remove the ECHO command.

有关更多信息,请阅读HELP DIRHELP SETHELP FOR.

For more information, read HELP DIR, HELP SET and HELP FOR.

这篇关于.bat批处理重命名为fname中的递增数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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