windows 使用通配符重命名cmd中的文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8780097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
renaming files in cmd using wildcards
提问by kru96
I'm writing a BAT file for renaming some files.
My files are *.jpg
where * is the file name and I want them to be *-thumb.jpg
.
我正在编写一个 BAT 文件来重命名一些文件。我的文件是*.jpg
* 是文件名,我希望它们是*-thumb.jpg
.
When trying to do RENAME *.jpg *-thumb.jpg
my files appear as *.jpg-thumb.jpg
.
尝试执行时,RENAME *.jpg *-thumb.jpg
我的文件显示为*.jpg-thumb.jpg
.
采纳答案by Peter Svensson
Something like:
就像是:
for %%f in (*.jpg) do rename "%%f" "%%~nf-thumb.jpg"
回答by dbenham
Actually the RENAME command alone can solve the problem, as long as there is only one .
in the name. Simply use many ?
instead of a single *
.
其实只用RENAME命令就可以解决问题,只要.
名字中只有一个即可。只需使用 many?
而不是单个*
.
REN *.jpg ????????????????????-thumb.*
Just make sure the number of ?
is at least as long as the longest file name that will be renamed.
只需确保数量?
至少与要重命名的最长文件名一样长。
You can ensure that names with multiple .
are not accidentally named by using many ?
in the source mask as well. The following will rename "abc.jpg" to "abc-thumb.jpg", but will leave "abc.xyz.jpg" alone.
您还可以.
通过?
在源掩码中使用 many来确保不会意外命名具有多个的名称。以下内容将“abc.jpg”重命名为“abc-thumb.jpg”,但不会单独留下“abc.xyz.jpg”。
REN ????????????????????.jpg ????????????????????-thumb.*
You can rename a file with two dots like "abc.xyz.jpg" using the following.
您可以使用以下命令重命名带有两个点的文件,例如“abc.xyz.jpg”。
REN ????????????.????????????.jpg ????????????.????????????-thumb.*
The pattern can be extended for any number of dots in the name.
该模式可以扩展为名称中任意数量的点。
See How does the Windows RENAME command interpret wildcards?for more info.
请参阅Windows RENAME 命令如何解释通配符?了解更多信息。