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?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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"]);
}