重命名目录中的所有文件与Windows批处理脚本 [英] Rename all files in a directory with a Windows batch script
问题描述
我将如何写一个批处理或CMD文件,将重命名目录中的所有文件?我使用Windows。
更改此:
750_MOT_Forgiving_120x90.jpg
751_MOT_Persecution_1_120x90.jpg
752_MOT_Persecution_2_120x90.jpg
753_MOT_Hatred_120x90.jpg
754_MOT_Suffering_120x90.jpg
755_MOT_Freedom_of_Religion_120x90.jpg
756_MOT_Layla_Testimony_1_120x90.jpg
757_MOT_Layla_Testimony_2_120x90.jpg
要这样:
750_MOT_Forgiving_67x100.jpg
751_MOT_Persecution_1_67x100.jpg
752_MOT_Persecution_2_67x100.jpg
753_MOT_Hatred_67x100.jpg
754_MOT_Suffering_67x100.jpg
755_MOT_Freedom_of_Religion_67x100.jpg
756_MOT_Layla_Testimony_1_67x100.jpg
757_MOT_Layla_Testimony_2_67x100.jpg
一个FOR语句遍历名称(类型 FOR /?
寻求帮助),以及字符串搜索和替换(键入 SET /?
寻求帮助)。
关闭@echo
SETLOCAL enableDelayedExpansion
为%% f由于(* 120x90.jpg)做(
设置名称= %% F
仁!名字! !名字:120x90 = 67x100!
)
的更新 - 2012-11-07
我已经研究了如何用通配符重命名命令处理:如何在Windows RENAME命令间preT通配符一>
原来,这个特殊的问题可以通过重命名命令,而无需任何一个批处理脚本变得非常容易解决的。
仁* _120x90.jpg * _67x100。*
字符 _
后的数字并不重要。重命名仍然会正常工作,如果 120x90
成为 X
或 XXXXXXXXXX
。这个问题的重要方面是,过去之间的整个文本_
和。
将被替换。
How would I write a batch or cmd file that will rename all files in a directory? I am using Windows.
Change this:
750_MOT_Forgiving_120x90.jpg
751_MOT_Persecution_1_120x90.jpg
752_MOT_Persecution_2_120x90.jpg
753_MOT_Hatred_120x90.jpg
754_MOT_Suffering_120x90.jpg
755_MOT_Freedom_of_Religion_120x90.jpg
756_MOT_Layla_Testimony_1_120x90.jpg
757_MOT_Layla_Testimony_2_120x90.jpg
To this:
750_MOT_Forgiving_67x100.jpg
751_MOT_Persecution_1_67x100.jpg
752_MOT_Persecution_2_67x100.jpg
753_MOT_Hatred_67x100.jpg
754_MOT_Suffering_67x100.jpg
755_MOT_Freedom_of_Religion_67x100.jpg
756_MOT_Layla_Testimony_1_67x100.jpg
757_MOT_Layla_Testimony_2_67x100.jpg
A FOR statement to loop through the names (type FOR /?
for help), and string search and replace (type SET /?
for help).
@echo off
setlocal enableDelayedExpansion
for %%F in (*120x90.jpg) do (
set "name=%%F"
ren "!name!" "!name:120x90=67x100!"
)
UPDATE - 2012-11-07
I've investigated how the RENAME command deals with wildcards: How does the Windows RENAME command interpret wildcards?
It turns out that this particular problem can be very easily solved using the RENAME command without any need for a batch script.
ren *_120x90.jpg *_67x100.*
The number of characters after the _
does not matter. The rename would still work properly if 120x90
became x
or xxxxxxxxxx
. The important aspect of this problem is that the entire text between the last _
and the .
is replaced.
这篇关于重命名目录中的所有文件与Windows批处理脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!