[代码] [Shell/批处理]代码
view sourceprint?
01
@echo off
02
echo *******文件批量重命名*******
03
echo ╔------------------------------------╗
04
echo Version 0.0.1
05
echo 版权没有,翻版不究
06
echo Change 2011-04-28
07
echo ╚------------------------------------╝
08
09
echo.
10
echo *请依次输入新文件名和文件类型
11
echo *若文件名为空,按当前目录名操作
12
echo.
13
14
set /p filename=新文件名:
15
IF "%filename%"=="" set "filename=%%~ni"
16
17
set /p suffix=文件类型:
18
IF "%suffix%"=="" echo.文件类型不能为空 &goto error
19
IF NOT EXIST *.%suffix% echo.不存在该格式文件 &goto error
20
21
setlocal ENABLEDELAYEDEXPANSION
22
for /r %%i in (.) do (
23
set n=1000
24
for /f "delims=" %%a in (' dir /b "%%i\*.%suffix%" 2^>nul ') do (
25
set /a n+=1
26
ren "%%i\%%a" "%filename%"!n:~1!%%~xa
27
)
28
)
29
30
echo. &pause
31
exit
32
33
:error
34
echo. &pause
view sourceprint?
01
@echo off
02
echo *******文件批量重命名*******
03
echo ╔------------------------------------╗
04
echo Version 0.0.1
05
echo 版权没有,翻版不究
06
echo Change 2011-04-28
07
echo ╚------------------------------------╝
08
09
echo.
10
echo *请依次输入新文件名和文件类型
11
echo *若文件名为空,按当前目录名操作
12
echo.
13
14
set /p filename=新文件名:
15
IF "%filename%"=="" set "filename=%%~ni"
16
17
set /p suffix=文件类型:
18
IF "%suffix%"=="" echo.文件类型不能为空 &goto error
19
IF NOT EXIST *.%suffix% echo.不存在该格式文件 &goto error
20
21
setlocal ENABLEDELAYEDEXPANSION
22
for /r %%i in (.) do (
23
set n=1000
24
for /f "delims=" %%a in (' dir /b "%%i\*.%suffix%" 2^>nul ') do (
25
set /a n+=1
26
ren "%%i\%%a" "%filename%"!n:~1!%%~xa
27
)
28
)
29
30
echo. &pause
31
exit
32
33
:error
34
echo. &pause