把下面代码,用记事本编辑,后缀改成.bat
@echo off :start setlocal enabledelayedexpansion set isrun=n echo 请把包含要处理的文件的[文件夹]拖动到此处,回车确定 set dir=n&set /p dir= if "%dir:"=%"=="n" cls&goto start cls&echo ==================================== :run for /f "delims=" %%i in ('dir /s /b /a:-d %dir%\*.*') do ( set full=%%~dpnxi set exten=%%~xi set path=%%~dpi set path=!path:~0,-1! for /f "delims=" %%j in ("!path!") do set path=%%~nj if /i "!isrun!"=="n" ( echo ren "!full!" "!path!!exten!" ) else ( ren "!full!" "!path!!exten!" echo 更名为:"!path!!exten!" ) ) echo ==================================== if /i "%isrun%"=="n" ( echo 即将执行以上操作,是否执行[Y/N] set isrun=n&set /p isrun= if /i "!isrun!"=="y" ( goto run ) else ( cls&goto start ) ) else ( echo.&echo 更名完成! echo 任意键返回&pause>nul&cls&goto start )