Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
273 views
in Technique[技术] by (71.8m points)

windows - 重命名cmd中的多个文件(Rename multiple files in cmd)

If I have multiple files in a directory and want to append something to their filenames, but not to the extension, how would I do this?

(如果我在一个目录中有多个文件,并且想要在文件名中附加一些内容,但不希望在扩展名中附加一些内容,我该怎么做?)

I have tried the following, with test files file1.txt and file2.txt :

(我已经尝试了以下测试文件file1.txtfile2.txt :)

ren *.txt *1.1.txt

This renames the files to file1.1.txt and file2.txt1.1.txt

(这会将文件重命名为file1.1.txtfile2.txt1.1.txt)

I want the files to be file1 1.1.txt and file2 1.1.txt

(我希望文件为file1 1.1.txtfile2 1.1.txt)

Will this be possible from cmd or do I need to have a bat file to do this?

(从cmd可以做到这一点还是我需要一个bat文件来做到这一点?)

What about PowerShell?

(那PowerShell呢?)

  ask by Morne translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Make sure that there are more ?

(确保还有更多?)

than there are characters in the longest name:

(最长名称中不能包含字符:)

ren *.txt "???????????????????????????? 1.1.txt"

See How does the Windows RENAME command interpret wildcards?

(请参阅Windows RENAME命令如何解释通配符?)

for more info.

(有关更多信息。)

New Solution - 2014/12/01

(新解决方案-2014/12/01)

For those who like regular expressions, there is JREN.BAT - a hybrid JScript/batch command line utility that will run on any version of Windows from XP forward.

(对于那些喜欢正则表达式的人,还有JREN.BAT -JScript / batch混合命令行实用程序,它将在XP以后的任何Windows版本上运行。)

jren "^.*(?=.)" "$& 1.1" /fm "*.txt"

or

(要么)

jren "^(.*)(.txt)$" "$1 1.1$2" /i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...