Diskpart info

Sometimes you may want to get disk partition information.

The following is written for an English version of Windows Diskpart. It may not work correctly for a different language.


@Echo OffSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION
for /f "tokens=2,3,4,5,6,7" %%B in ('^(echo sel disk %1^&echo list part^)^|diskpart^|FIND /I "Partition %2"') do set L_PART=%%B & set L_TYPE=%%C & set /A L_SIZE=%%D & set L_UNITS=%%E
echo L_PART=%L_PART% L_TYPE=%L_TYPE% L_SIZE=%L_SIZE% L_UNITS=%L_UNITS%

echo -----------
for /f %%A in ('^(echo sel disk %1^&echo list part^)^|diskpart^|FIND /I "Partition %2"') do (for /f "tokens=*" %%B in ('^(echo sel disk %1^&echo sel part %2^&echo detail par^)^|diskpart^|FIND /I "*"') do set DLINE=%%B)
::          1         2         3         4         5         6         7::01234567890123456789012345678901234567890123456789012345678901234567890123456789::  ----------  ---  -----------  -----  ----------  -------  ---------  --------::* Volume 11    O   M2 PTN2      FAT32  Partition     29 GB  Healthy::  Volume ###  Ltr  Label        Fs     Type        Size     Status     InfoREM echo DLINE=%DLINE%REM Clear variablesset L_VNUM=set L_LETT=set L_LABEL=set L_FS=set LP_TYPE=set L_SIZE=set L_UNITS=
REM Get characters from line and trim beginning and end of spaces (assumes no " or ! or & in the string!)if NOT "%DLINE%"=="" (set /A L_VNUM=%DLINE:~9,3%set L_LETT=%DLINE:~15,1%set L_LABEL=%DLINE:~19,11%set L_FS=%DLINE:~32,5%set LP_TYPE=%DLINE:~39,11%set /A L_SIZE=%DLINE:~51,4%set L_UNITS=%DLINE:~56,2%call :_trimAll "%%L_LABEL%% set L_LABEL=!str!call :_trimAll "%%L_FS%% set L_FS=!str!call :_trimAll "%%LP_TYPE%% set LP_TYPE=!str!call :_trimAll "%%L_UNITS%% set L_UNITS=!str!call :_trimAll "%%L_LETT%%set L_LETT=!str!)
echo L_VNUM=*%L_VNUM%* LETTER=*%L_LETT%* LABEL=*%L_LABEL%* FS=*%L_FS%* LP_TYPE=*%LP_TYPE%* L_SIZE=*%L_SIZE%* L_UNITS=*%L_UNITS%*

ENDLOCALgoto :EOF

REM  ==== SUBROUTINES =====
:_trimAll:: subfunction:: trailing exclaim is required as explained by Jeb at:: https://www.dostips.com/forum/viewtopic.php?p=6933#p6933set "str=%~1" !exit /b 0

LP_TYPE may say 'Removable' for a flash drive, etc.

Usage: getpart.cmd  diskno  partno