直接替换
@echo off CHCP 65001 & REM 改成utf-8编码 @echo off set 拟替换=.下载 set 拟替换成= & REM 替换成空 for /f "delims=" %%i in ('dir /a /b') do ( setlocal EnableDelayedExpansion set str1=%%i set "str1=!str1:%拟替换%=%拟替换成%!" echo %%i echo !str1! ren "%%i" "!str1!" endlocal ) pause
交互方式
@echo off @REM 改成utf-8编码 CHCP 65001 set /p w=请输入文件格式(不要输入 .号): set /p wf=请输入要修改的文字(以回车结束): set /p cb=请输入要改成的文字(若是删除则直接回车,以回车结束): for /f "delims=" %%i in ('dir /b /a-d "*.%w%"' ) do ( set str1=%%i setlocal EnableDelayedExpansion set "str1=!str1:%wf%=%cb%!" ren "%%i" "!str1!" endlocal )
pause