Тома списка DiskPart не дадут вам свободного места, но я предполагаю, что это был только пример.
Эта партия даст вам максимальную емкость вашей системы.
Он использует достаточно конструкций, чтобы вы работали с вашими требованиями ...
Вам нужно будет поместить следующее в командный файл
@echo off
echo ****************************************************
echo *** Give maximum drive size on a given system ****
echo ****************************************************
echo *** This script shows various batch constructs. ****
echo *** Use at your own risk - no warranty given ****
echo *** that's fit for any intended purpose :-)) ****
echo *** or that it's error free ****
echo ****************************************************
echo.
REM All of our vars will be local - we do not want to pollute environment. For more info exec 'help setlocal' from cmdline
REM implied endlocal will be issued at the end, no need to insert it
setlocal
REM name of temp file we will use
set tmpFile=tmp.txt
REM power will store multiplier we are currently working in
set power=0
REM maximum found drive size
set maxSize=0
REM Enable delayed expansion - must be on, otherwise all vars will be expanded on input. For more info exec 'help setlocal' from cmdline
setlocal enabledelayedexpansion
REM enable extensions (on by default). Please see help setlocal
setlocal enableextensions
REM get input from user. For more info exec 'help set' from cmdline
set /P cmd=Give diskpart command you want to run [list volume]
REM set default command if user did not set anything
if NOT DEFINED cmd set cmd=list volume
REM set file to contain command we want to run
echo %cmd%>%tmpFile%
REM Skip 8 first lines, then read each line as token. For more info exec 'help for' from cmdline
REM use of backquote will enable us to use temp file with spaces in name
set ERRORLEVEL=0
for /f "tokens=* skip=8 usebackq" %%i in (`diskpart /s %tmpFile%`) do (
set line=%%i
REM read 5 chars from input token, starting at char 49, convert it to number and assign to env var. For more info exec 'help set' from cmdline
REM This also shows delayed expansion convention (!var!).
set /A tsize=!line:~49,5!*1
REM test for unequality (we want to run body only if given size is not 0). For more info exec 'help if' from cmdline
REM see also other operators used (LSS, GEQ
if !tsize! NEQ 0 (
REM it's not possible to do most obvious (multiplication) as this would overflow.
REM '(' is block character. Look how they are positioned, it has to be this way!
REM Mind also where you can put spaces!
REM 'set a=7' is different to 'set a=7 '
set unit=!line:~54,2!
REM Mind use of '
if '!unit!'==' B' (
if !power! LSS 1 (
set power=1
set maxSize=!tSize!
)
if !power!==1 (
if !tsize! GEQ !maxsize! (
set maxSize=!tsize!
set maxUnit=!unit!
set maxDrive=!line!
)
)
)
if !unit!==KB (
if !power! LSS 3 (
set power=3
set maxSize=!tSize!
)
if !power!==3 (
if !tsize! GEQ !maxsize! (
set maxSize=!tsize!
set maxUnit=!unit!
set maxDrive=!line!
)
)
)
if !unit!==MB (
if !power! LSS 6 (
set power=6
set maxSize=!tSize!
)
if !power!==6 (
if !tsize! GEQ !maxsize! (
set maxSize=!tsize!
set maxUnit=!unit!
set maxDrive=!line!
)
)
)
if !unit!==GB (
if !power! LSS 9 (
set power=9
set maxSize=!tSize!
)
if !power!==9 (
if !tsize! GEQ !maxsize! (
set maxSize=!tsize!
set maxUnit=!unit!
set maxDrive=!line!
)
)
)
)
)
REM cleanup
del %tmpFile% /Q
REM this prints empty line
echo.
echo Your max drive is: !maxSize! !maxUnit!
echo.
echo Drive details:
echo !maxDrive!