如何使用 DOS 命令从文件夹中的文件列表的文件名中删除单个字符?
How to remove a single character from the filename of a list of files in a folder using DOS command?
我有一个这样的文件列表:
icone1.gif
icone2.gif
icone1.gif
icone11.gif
icone12.gif
icone13.gif
icone14.gif
icone15.gif
我想从中删除 'e',这样他们就会 icon1.gif、icon2.gif 等等...
我在 DOS 命令提示符下试过:
ren icone*.gif icon*.gif
没有成功。
通过在命令提示符下键入 "notepad go.bat" 并按回车键并将其放入文件夹中创建一个批处理文件,然后保存并退出记事本:
for %%i in ("*.gif") do (set fname=%%i) & call :rename
goto :eof
:rename
::Cuts off 1st five chars, then appends Icon and the remaining chars
ren "%fname%" "Icon%fname:~5%"
goto :eof
双击 windows 中的批处理文件或在命令提示符下键入 go 并按 enter
请参阅 How does the Windows RENAME (REN) command interpret wildcards? 了解可以解释为什么您的命令不起作用的规则。
假设您所有的文件名在 "icone" 之后都有一个数字(真的只关心您永远不会在 "icone" 之后有另一个 "e"),那么下面的一个衬垫将从命令行。
for /f "tokens=1* delims=eE" %A in ('dir /b icone*.gif') do @ren "%Ae%B" "%A%B"
如果将命令放在批处理脚本中,则将百分比加倍。
对于真正简单而强大的解决方案,请使用我的 JREN.BAT regular expression renaming utility 纯脚本(混合 JScript/batch),它可以在任何 Windows XP 以后的机器上本地运行。
jren "^(icon)e(.*\.jpg)" "" /i
我有一个这样的文件列表: icone1.gif icone2.gif icone1.gif icone11.gif icone12.gif icone13.gif icone14.gif icone15.gif
我想从中删除 'e',这样他们就会 icon1.gif、icon2.gif 等等...
我在 DOS 命令提示符下试过:
ren icone*.gif icon*.gif
没有成功。
通过在命令提示符下键入 "notepad go.bat" 并按回车键并将其放入文件夹中创建一个批处理文件,然后保存并退出记事本:
for %%i in ("*.gif") do (set fname=%%i) & call :rename
goto :eof
:rename
::Cuts off 1st five chars, then appends Icon and the remaining chars
ren "%fname%" "Icon%fname:~5%"
goto :eof
双击 windows 中的批处理文件或在命令提示符下键入 go 并按 enter
请参阅 How does the Windows RENAME (REN) command interpret wildcards? 了解可以解释为什么您的命令不起作用的规则。
假设您所有的文件名在 "icone" 之后都有一个数字(真的只关心您永远不会在 "icone" 之后有另一个 "e"),那么下面的一个衬垫将从命令行。
for /f "tokens=1* delims=eE" %A in ('dir /b icone*.gif') do @ren "%Ae%B" "%A%B"
如果将命令放在批处理脚本中,则将百分比加倍。
对于真正简单而强大的解决方案,请使用我的 JREN.BAT regular expression renaming utility 纯脚本(混合 JScript/batch),它可以在任何 Windows XP 以后的机器上本地运行。
jren "^(icon)e(.*\.jpg)" "" /i