- @echo off
-
- :Input_Folder
- echo 请输入文件夹路径(或拖放文件夹到本窗口):
- set Folder=
- set /p Folder=
-
- if not defined Folder goto Input_Folder
- if not exist "%Folder:"=%" (
- echo * 错误:不存在该文件夹
- goto Input_Folder
- )
-
- :Input_OldExt
- set OldExt=
- set /p OldExt=请输入原后缀名:
-
- if not defined OldExt goto Input_OldExt
-
- :Input_NewExt
- set NewExt=
- set /p NewExt=请输入新后缀名:
-
- if not defined NewExt goto Input_NewExt
-
- rem 去除路径中的引号、后缀中的“.”及前面的字符
- set "Folder=%Folder:"=%"
- set "OldExt=%OldExt:*.=%"
- set "NewExt=%NewExt:*.=%"
-
- for /f "delims=" %%i in ('dir /a:-d /b /s "%Folder%\*.%OldExt%"') do (
- set fPath=%%~dpi
- set fName=%%~ni
- set fAttr=%%~ai
- SetLocal EnableDelayedExpansion
-
- rem 判断有没有“系统”和“隐藏”属性,有则去除
- set AttrList=
- if "!fAttr:s=!" neq "!fAttr!" set AttrList= s
- if "!fAttr:h=!" neq "!fAttr!" set AttrList=!AttrList! h
- if defined AttrList (
- attrib !AttrList: = -! "!fPath!!fName!.!OldExt!"
- )
-
- rem 计算文件名的字符个数
- set /a n = 8189, b = 0
- for /l %%a in (1 1 13) do (
- set /a "a = (n - b) / 2 + b"
- for %%b in (!a!) do (
- if "!fName:~%%b,1!"=="" (set n=!a!) else set b=!a!
- )
- )
-
- rem 颠倒文件名
- set /a n -= 1
- for /l %%n in (0 1 !n!) do (
- set NewName=!fName:~%%n,1!!NewName!
- )
-
- rem 重命名
- ren "!fPath!!fName!.!OldExt!" "!NewName!.!NewExt!"
-
- rem 如果之前修改了文件属性,则改回去
- if defined AttrList (
- attrib !AttrList: = +! "!fPath!!NewName!.!NewExt!"
- )
-
- EndLocal
- )
复制代码
[ 本帖最后由 tmplinshi 于 2011-1-23 10:23 编辑 ] |