bat 批量更改文件名

通过如下批处理命令可实现批量更改文件名:

@echo 
set DIR="%cd%"
echo DIR=%DIR%
set /p ext=文件类型:
set /p find=要替换内容:
set /p replace=替换内容:
for /f "delims=" %%i in ('dir /b /a-d "*.%ext%"' ) do ( 

set str1=%%i 
setlocal EnableDelayedExpansion
set "str1=!str1:%find%=%replace%!"
ren "%%i" "!str1!"
endlocal
)
pause

因为ren命令第二个参数必须是文件名,第一个参数可以是相对路径也可以是绝对路径,所以,在循环文件的时候,务必加入/b (参数:将只显示文件名与扩展名),模式是绝对路径。

猜你喜欢

转载自www.cnblogs.com/lcawen/p/10339275.html