2023年12月18日 星期一

Get all drive letters of a drive/disk

 

Here's an example , feel free to try and modify it as necessary.

@For /F Delims^=^= %%Z In ('Set Disk 2^>Nul')Do @Set "%%Z="
@For /F Delims^= %%V In ('WMIC DiskDrive Assoc^
 /AssocClass:Win32_DiskDriveToDiskPartition 2^>NUL^|Find /I "Disk #"'
)Do @For /F Tokens^=2Delims^=^" %%W In ("%%V"
)Do @For /F Tokens^=2^,4Delims^=^" %%X In ('WMIC Path^
 Win32_LogicalDiskToPartition 2^>NUL^|Find "%%W" 2^>Nul'
)Do @For /F "Tokens=2Delims=#," %%Z In ("%%X")Do @If Defined Disk%%Z (
    Call Set "Disk%%Z=%%Disk%%Z%% %%Y")Else Set "Disk%%Z=%%Y")
@Set Disk 2>NUL&&Pause

Example output, (Windows 7):

Disk0=C:
Disk2=E:
Disk3=F: G: H:
Press any key to continue . . .


More about batch file skill

https://stackoverflow.com/questions/tagged/batch-file


https://stackoverflow.com/questions/56850070/get-all-drive-letters-of-a-drive-disk


沒有留言: