获取 drive/disk 的所有盘符
Get all drive letters of a drive/disk
获取drive/disk
的所有盘符
示例:
Disk0 - C:, D:, E:
Disk1 - F:, G:, H:
我想获取drive/disk的所有盘符。我试过代码:
WMIC PATH Win32_DiskDrive WHERE 'Index=0' Assoc:list /AssocClass:Win32_Volume
WMIC PATH Win32_DiskDrive WHERE 'Index=0' Assoc:list /ResultClass:Win32_DiskPartition
但是结果不是我想要的
这是一个示例batch-file,请随意尝试并根据需要进行修改。
@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
示例输出,(Windows 7):
Disk0=C:
Disk2=E:
Disk3=F: G: H:
Press any key to continue . . .
我和你的批次断线了。对吗?
::@ECHO OFF
@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
您可能需要先了解磁盘类型。我更喜欢 fsutil,它随 Windows:
一起提供
R:\>for %d in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO @fsutil.exe fsinfo drivetype %d:\
A:\ - No such Root Directory
B:\ - No such Root Directory
C:\ - Fixed Drive
D:\ - Fixed Drive
E:\ - No such Root Directory
F:\ - No such Root Directory
G:\ - No such Root Directory
H:\ - No such Root Directory
I:\ - No such Root Directory
J:\ - No such Root Directory
K:\ - Removable Drive
L:\ - No such Root Directory
M:\ - No such Root Directory
N:\ - No such Root Directory
O:\ - No such Root Directory
P:\ - Fixed Drive
Q:\ - No such Root Directory
R:\ - Fixed Drive
S:\ - No such Root Directory
T:\ - No such Root Directory
U:\ - No such Root Directory
V:\ - No such Root Directory
W:\ - CD-ROM Drive
X:\ - Fixed Drive
Y:\ - Remote/Network Drive
Z:\ - No such Root Directory
获取drive/disk
的所有盘符示例:
Disk0 - C:, D:, E:
Disk1 - F:, G:, H:
我想获取drive/disk的所有盘符。我试过代码:
WMIC PATH Win32_DiskDrive WHERE 'Index=0' Assoc:list /AssocClass:Win32_Volume
WMIC PATH Win32_DiskDrive WHERE 'Index=0' Assoc:list /ResultClass:Win32_DiskPartition
但是结果不是我想要的
这是一个示例batch-file,请随意尝试并根据需要进行修改。
@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
示例输出,(Windows 7):
Disk0=C:
Disk2=E:
Disk3=F: G: H:
Press any key to continue . . .
我和你的批次断线了。对吗?
::@ECHO OFF
@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
您可能需要先了解磁盘类型。我更喜欢 fsutil,它随 Windows:
一起提供R:\>for %d in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO @fsutil.exe fsinfo drivetype %d:\
A:\ - No such Root Directory
B:\ - No such Root Directory
C:\ - Fixed Drive
D:\ - Fixed Drive
E:\ - No such Root Directory
F:\ - No such Root Directory
G:\ - No such Root Directory
H:\ - No such Root Directory
I:\ - No such Root Directory
J:\ - No such Root Directory
K:\ - Removable Drive
L:\ - No such Root Directory
M:\ - No such Root Directory
N:\ - No such Root Directory
O:\ - No such Root Directory
P:\ - Fixed Drive
Q:\ - No such Root Directory
R:\ - Fixed Drive
S:\ - No such Root Directory
T:\ - No such Root Directory
U:\ - No such Root Directory
V:\ - No such Root Directory
W:\ - CD-ROM Drive
X:\ - Fixed Drive
Y:\ - Remote/Network Drive
Z:\ - No such Root Directory