我想这样重命名该文件:
File 1.pdf > 1.pdf
File 2.pdf > 2.pdf
..
File 10.pdf >10.pdf
File 11.pdf >11.pdf
File1 1.pdf >12.pdf
File1 2.pdf >13.pdf
..
此代码有效,但无法对其进行排序:
@echo off & setlocal EnableDelayedExpansion
set a=1
for /f "delims=" %%i in ('dir /b *.pdf') do (
ren "%%i" "!a!.pdf"
set /a a+=1
)
结果是:
File 1.pdf > 1.pdf
File 10.pdf > 2.pdf
File 11.pdf > 3.pdf
@echo off
setlocal enabledelayedexpansion
if "%~1" == "stage1" goto :stage1
if "%~1" == "stage2" goto :stage2
if not "%~1" == "" exit /b 1
cmd /c "%~f0" stage1 | sort | cmd /c "%~f0" stage2
exit /b 0
:stage1
for /f "delims=" %%A in ('dir /b *.pdf') do (
for /f "tokens=1,*" %%B in ("%%~nA") do (
set "token1=%%~B "
set "token2= %%~C"
echo "!token1:~0,20!"^|"!token2:~-20!"^|"%%~A"
)
)
exit /b 0
:stage2
set i=0
for /f "delims=" %%A in ('more') do (
set /a "i+=1"
for /f "tokens=3 delims=|" %%B in ("%%~A") do (
echo ren "%%~B" "!i!.pdf"
)
)
exit /b 0
标签stage1
用空格填充文件名的2个标记,然后将每个标记修剪为20个字符的长度。每行均以表示"token1 padded"|"token2 padded"|"full filename"
,并通过管道传递到sort
,然后通过管道传递给标签stage2
以进行索引和重命名。
ren
如果测试良好,请删除命令前面的回显。
输出:
ren "File 1.pdf" "1.pdf" ren "File 2.pdf" "2.pdf" ren "File 10.pdf" "3.pdf" ren "File 11.pdf" "4.pdf" ren "File1 1.pdf" "5.pdf" ren "File1 2.pdf" "6.pdf"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句