1

我一直在编写列出磁盘所有分区的代码,但我发现了一个问题。WMI的Win32_DiskDrive属性Partitions显示一个测试磁盘有 5 个分区,但我只能列出其中的四个(最后两个分区显示为只有一个)。最后两个分区是主分区,但一个是 SWAP 分区,另一个是 Linux 分区。

4

2 回答 2

2

我认为这应该可以解决问题:

    /// <summary>
    /// Loads all Drives of the Computer and returns a List.
    /// </summary>
    private List<DriveInfo> LoadDrives()
    {
        var drives = new List<DriveInfo>();
        foreach (DriveInfo drive in DriveInfo.GetDrives())
        {
            if (drive.IsReady)
            {
                drives.Add(drive);
            }
        }
        return drives;
    }
于 2013-06-18T18:31:22.530 回答
1

我相信你想要的是string[] System.IO.Directory.GetLogicalDrives()

对于string您使用的每一个GetLogicalDrives,您都可以创建一个System.IO.DriveInfo对象,该对象将提供有关逻辑驱动器的各种信息。

DriveInfo.GetDrives()可能是上述两个步骤的捷径。不过我并不完全确定,文档也不是很清楚。

于 2013-06-18T18:30:52.737 回答