批处理-给pdf和文件夹编号

1.给所有文件前加编号(英语pdf适用)

@echo off
setlocal enabledelayedexpansion
for /f "tokens=*" %%i in ('dir/b/a-d') do (
set /a cnt+=1
set fn=000!cnt!
ren "%%i" "!fn:~-3!%%i")
pause
 

2.文件加序号(中文pdf适用)

@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in ('dir /b /a-d') do (
for /f "tokens=1-4" %%a in ("%%i") do (
if not "%%i"=="%~nx0" ren "%%i" "%%a%%b%%c%%d"||del /f "%%i"
))
for /f "delims=" %%i in ('dir /b /a-d') do (
if not "%%i"=="%~nx0" (
set /a x+=1
ren "%%i" "!x!.%%i"
))

3.文件夹加序号(仅测试了中文文件夹)

@echo off
cd /d %~dp0
setlocal enabledelayedexpansion
set num=1
for /F "delims=" %%i in ('dir /B /A:D') do (
ren "%%i" "!num!-%%i"
set /A num=!num!+1
)

猜你喜欢

转载自blog.csdn.net/qq_40431700/article/details/120518378