告诉如果驱动器分区或硬盘分开 [英] Tell if a Drive is a partition or a separate HDD
问题描述
我写我自己的文件搜索(为什么?因为我想/能 - 不找一个现有的程序)。我可以通过使用 DriveInfo获得在C#中的所有驱动器。 GetDrives()方法。理想情况下,我想只在是独立的磁盘驱动器,并为同一驱动器上运行它们的顺序分区并行运行搜索。这样,我不会对不断追求的GetDrives驱动器返回的所有分区或可移动介质。我知道我可以告诉大家,如果它是一个USB驱动器与一个硬盘的类型?我怎样才能做到这将DriveInfo或任何其他方法,它
I am writing my own file search (why because I want to / can - not looking for an existing program). I can get all the drives in c# by using the DriveInfo.GetDrives() method. Ideally I would like to run the search in parallel only on drives that are separate disk and for partitions that are on the same drive run them sequential. This way I will not cause the drives on constantly seek as the GetDrives returns all partitions or removable media. I know I can tell the type if it is a USB Drives vs. a HDD? How can I accomplish this will the DriveInfo or any other methodology that?
推荐答案
的此相关的问题展示了如何找出使用WMI(在 System.Management
):
This related question shows how to find out using WMI (found in System.Management
):
var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskPartition");
foreach (var queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_DiskPartition instance");
Console.WriteLine("Name:{0}", (string)queryObj["Name"]);
Console.WriteLine("Index:{0}", (uint)queryObj["Index"]);
Console.WriteLine("DiskIndex:{0}", (uint)queryObj["DiskIndex"]);
Console.WriteLine("BootPartition:{0}", (bool)queryObj["BootPartition"]);
}
这篇关于告诉如果驱动器分区或硬盘分开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!