code1- @echo off
- set /p str1= 请输入要替换的文件(文件夹)名字符串(可替换空格):
- set /p str2= 请输入替换后的文件(文件夹)名字符串(去除则直接回车):
- echo.
- echo 正在修改文件(夹)名中,请稍候……
- for /f "delims=" %%a in ('dir /s /b ^|sort /+65535') do (
- if "%%~nxa" neq "%~nx0" (
- set "file=%%a"
- set "name=%%~na"
- set "extension=%%~xa"
- call set "name=%%name:%str1%=%str2%%%"
- call set "name=%%name:* =%%"
- setlocal enabledelayedexpansion
- ren "!file!" "!name!!extension!" 2>nul
- endlocal
- )
- )
- pause
复制代码
code 2
- @echo off
- rem 最多支持文件名含10个"_"
- for /f "delims=" %%i in ('dir /b /s /a-d *.jpg') do (
- set "newName=%%~nxi"
- set "oldName=%%~fi"
- setlocal enabledelayedexpansion
- for /l %%l in (1,1,10) do (
- set "newName=!newName:*_=!"
- set "newName=!newName:* =!"
- )
- echo ren "!oldName!" "!newName!"
- ren "!oldName!" "!newName!"
- endlocal
- )
- pause
复制代码
|