bat 批量更改文件名

经过以下批处理命令可实现批量更改文件名:spa

@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 (参数:将只显示文件名与扩展名),模式是绝对路径。code

相关文章
相关标签/搜索