Вы можете добавить цифры влево к нулю, чтобы сравнить их с той же шириной, и затем сравнить строки:
@echo off
setlocal EnableDelayedExpansion
set "DiskIDFinal=" & set "DiskFreeFinal=000000000000000000000000"
for /F "skip=1 delims=" %%x in ('"wmic.exe logicaldisk where DriveType=3 get DeviceID,FreeSpace,Size"') do (
for /F "tokens=1-3" %%a in ("%%x") do (
rem // Pad number with 24 zeros to the left, then compare the right-most 24 digits:
set "DiskID=%%a" & set "DiskFree=000000000000000000000000%%b"
if "!DiskFree:~-24!" gtr "!DiskFreeFinal:~-24!" (
set "DiskIDFinal=!DiskID!" & set "DiskFreeFinal=!DiskFree:~-24!"
)
)
)
rem // Remove leading zeros from final number:
for /F "tokens=* delims=0" %%z in ("!DiskFreeFinal!") do set "DiskFreeFinal=%%z"
if not defined DiskFreeFinal set "DiskFreeFinal=0"
echo Biggest free space is on drive: %DiskIDFinal% (%DiskFreeFinal%)
endlocal
Кроме того, вы можете разделить числа на две части и сравнить их по отдельности:
@echo off
setlocal EnableDelayedExpansion
set "DiskIDFinal="
set /A "DiskFreeFinalHi=0, DiskFreeFinalLo=0"
for /F "skip=1 delims=" %%x in ('"wmic.exe logicaldisk where DriveType=3 get DeviceID,FreeSpace,Size"') do (
for /F "tokens=1-3" %%a in ("%%x") do (
set "DiskID=%%a" & set "DiskFreeLo=%%b"
rem // Split number into two parts for the right part to have 9 digits:
set "DiskFreeHi=!DiskFreeLo:~,-9!" & set "DiskFreeLo=!DiskFreeLo:~-9!"
for /F "tokens=* delims=0" %%z in ("!DiskFreeLo!") do set "DiskFreeLo=%%z"
set /A "DiskFreeHi+=0, DiskFreeLo+=0"
if !DiskFreeHi! gtr !DiskFreeFinalHi! (
set "DiskIDFinal=!DiskID!"
set /A "DiskFreeFinalHi=DiskFreeHi, DiskFreeFinalLo=DiskFreeLo"
) else if !DiskFreeHi! equ !DiskFreeFinalHi! (
if !DiskFreeLo! gtr !DiskFreeFinalLo! (
set "DiskIDFinal=!DiskID!"
set /A "DiskFreeFinalHi=DiskFreeHi, DiskFreeFinalLo=DiskFreeLo"
)
)
)
)
rem // Recombine the two parts of the number:
set "DiskFreeFinalLo=000000000%DiskFreeFinalLo%"
for /F "tokens=* delims=0" %%z in ("%DiskFreeFinalHi%%DiskFreeFinalLo:~-9%") do set "DiskFreeFinal=%%z"
if not defined DiskFreeFinal set "DiskFreeFinal=0"
echo Biggest free space is on drive: %DiskIDFinal% (%DiskFreeFinal%)
endlocal