通过DOS命令批量重命名文件
以下为提供的两种方法:遍历当前目录下的所有文件名以.avi结尾的文件,然后权限规则进行修改(规则含义请自行查找资料)。第一种方法有缺陷,更改完所有的文件名后,会多改一次。请斟酌使用。第二种方法解决了第一个方法的不足。
方法一:
1 @echo off
2 setlocal enabledelayedexpansion
3
4 for /f "delims=" %%a in ('dir /a-d /s /b *.avi') do (
5 echo "``````````"
6 @for /f "tokens=1,2,3 delims=.[-]" %%b in ("%%~nxa") do (
7 set b1=%%b
8 set c2=%%c
9 set d3=%%d
10
11 set a=%%~nxa
12 echo [!b1!]
13 echo [!c2!]
14 echo [!d3!]
15 ren "!a!" "[!c2!].!b1!.[!d3!].avi"
16 )
17
2 setlocal enabledelayedexpansion
3
4 for /f "delims=" %%a in ('dir /a-d /s /b *.avi') do (
5 echo "``````````"
6 @for /f "tokens=1,2,3 delims=.[-]" %%b in ("%%~nxa") do (
7 set b1=%%b
8 set c2=%%c
9 set d3=%%d
10
11 set a=%%~nxa
12 echo [!b1!]
13 echo [!c2!]
14 echo [!d3!]
15 ren "!a!" "[!c2!].!b1!.[!d3!].avi"
16 )
17
18 )
方法二:
1 @echo off
2 setlocal enabledelayedexpansion
3 for /r %%a in (*.avi) do (
4
5 for /f "tokens=1,2,3,4,5 delims=.[]" %%b in ("%%~nxa") do (
6 set b=%%b
7 set c=%%c
8 set d=%%d
9 set e=%%e
10 set f=%%f
11 set a=%%a
12 echo [!d!]
13 ren "!a!" "[!d!].!b!.!e!.!f!"
14 )
15
16 )
17 pause
3 for /r %%a in (*.avi) do (
4
5 for /f "tokens=1,2,3,4,5 delims=.[]" %%b in ("%%~nxa") do (
6 set b=%%b
7 set c=%%c
8 set d=%%d
9 set e=%%e
10 set f=%%f
11 set a=%%a
12 echo [!d!]
13 ren "!a!" "[!d!].!b!.!e!.!f!"
14 )
15
16 )
17 pause