使用命令提示符按顺序重命名多个文件 [英] rename multiple files in order with command prompt

查看:90
本文介绍了使用命令提示符按顺序重命名多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些名称不同的文件.

I have some files with different names.

Leviathan.txt,Dragon.txt等

Leviathan.txt,Dragon.txt and so on

我想把它变成一个数字开始

I wanted to turn it into a digit begins

1.txt,2.txt,3.txt,4.txt等

1.txt,2.txt,3.txt,4.txt and so on

如何使用For和可以传递文件夹中数量文件的功能来像其他语言一样执行操作?

how to perform like other language by using For and function that can pass amount files in folder?

到目前为止,我知道的代码是dir和ren.我现在就卡住了.

my code so far i know is dir and ren. and i stuck now.

ren *.txt 1.txt

推荐答案

假定您现有的文件都没有被命名为n.txt之类的名称,其中n是一个数字,然后只需将CD放入您的文件夹,然后运行以下命令从命令行:

Assuming none of your existing files are already named something like n.txt, where n is a number, then simply CD to your folder, and run the following command from the command line:

for "tokens=1* delims=:" %A in ('dir /b *.txt^|findstr /n "^"') do @ren "%B" "%A.txt"

如果在批处理脚本中使用该命令,则将百分比加倍.

Double up the percents if you use the command within a batch script.

编辑

我忘记了 JREN.BAT实用程序-正则表达式重命名实用程序.它是纯脚本(混合JScript/批处理),可从XP开始在任何Windows计算机上本地运行.

I forgot about my JREN.BAT utility - a regular expression renaming utility. It is pure script (hybrid JScript/batch) that runs natively on any Windows machine from XP onward.

JREN具有内置的功能,可以将数字合并到每个新文件名中,此外,它还可以用零填充数字,以便DIR命令以数字顺序列出文件.默认数字宽度为3位数字,因此文件应为"001.txt","002.txt",..."010.txt",..."100.txt"等.

JREN has a built in ability to incorporate a number into each new file name, and as an added bonus, it can left pad the number with zeros so that a DIR command lists the files in numerical order. The default numeric width is 3 digits, so files would be like "001.txt", "002.txt', ... "010.txt", ... "100.txt", etc.

jren "^.*" "$n+'.txt'" /j /fm *.txt

/NPAD选项指定最小数字宽度,因此NTAB 1不产生填充,这是原始问题的要求.

The /NPAD option specifies the minimum numeric width, so NTAB 1 produces no padding, which is what the original question asked for.

jren "^.*" "$n+'.txt'" /j /fm *.txt /npad 1

由于JREN本身是批处理脚本,因此,如果将命令放在另一个批处理脚本中,则必须使用CALL JREN.

Since JREN is a batch script itself, you must use CALL JREN if you put the command within another batch script.

完整的文档可从命令提示符处通过 jren/?获得.|更多.我的控制台窗口配置有大缓冲区,因此我可以向后滚动以查看先前的输出,而不必担心将帮助传递到MORE.

Full documentation is available from the command prompt via jren /? | more. My console window is configured with a large buffer, so I can scroll back to see prior output, and I don't bother with piping the help to MORE.

这篇关于使用命令提示符按顺序重命名多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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