问题描述
我想写一个Windows批处理文件重新命名了一套基于其原始名称的文件。我基本上是想要做的是一个文件名中找到的文本,并与其他文本替换它。
例如,如果文件有命名结构家庭圣诞001.JPG我可能要改变它照片 - 圣诞001.JPG。即以 - 圣诞照片替换家庭圣诞。这仅仅是一个例子。
I'm trying to write a Windows batch file to rename a set of files based on their original name. What I essentially want to do is find text within a file name and replace it with other text.For example, if the files had the naming structure "Family Christmas 001.jpg" I might want to change it to "Photos - Xmas 001.jpg". ie replace "Family Christmas" with "Photos - Xmas". This is just an example.
我发现了一块code从这个网站,dbenham的用户,但这几乎完全是我后。在这个例子中,他的替代120x90,在文件名以67x100
这里的code:
I've found a piece of code from a user of this site, dbenham, that does almost exactly what I'm after. In this example he's replacing "120x90" in a filename to "67x100"Here's the code:
@echo off
setlocal enableDelayedExpansion
for %%F in (*120x90.jpg) do (
set "name=%%F"
ren "!name!" "!name:120x90=67x100!"
)
谁能帮我适应这个code,使其处理空间中的文件名?
Can anyone help me adapt this code to make it handle spaces in the file name?
感谢
推荐答案
所有你缺少的是的
语句内报价 - 按照你的例子:
All you're missing is quotes within the FOR
statement - to follow your example:
@echo off
setlocal enableDelayedExpansion
for %%F in ("Family Christmas*.jpg") do (
set "name=%%F"
ren "!name!" "!name:Family Christmas=Photos - Xmas!"
)
这篇关于批处理文件重命名 - 查找和替换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!