4

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?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Brad Semrad
  • 1,501
  • 1
  • 11
  • 19

1 Answers1

3

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"]);
}
Community
  • 1
  • 1
M.Babcock
  • 18,753
  • 6
  • 54
  • 84
  • So the DiskIndex is the physical drive? – Brad Semrad Feb 02 '12 at 14:41
  • From the [documentation for Win32_DiskPartition](http://msdn.microsoft.com/en-us/library/windows/desktop/aa394135(v=vs.85).aspx), DiskIndex is "Index number of the disk containing this partition." – M.Babcock Feb 02 '12 at 14:44
  • @Brad - Has the solution provided not worked for you? (You took away the answer...) – M.Babcock Feb 03 '12 at 03:22
  • How can you map the the Index to the Volume i.e C:\ is Index 0 on DiskIndex 0? – Brad Semrad Feb 03 '12 at 03:23
  • 2
    That should be a question for a *different* question... I've answered the question presented here. – M.Babcock Feb 03 '12 at 03:24
  • @M.Babcok Alright Ill create a different question but part of my solution was using the GetDrives which only has the volume label (the Name property). I thought the method would allow based on the Name and other properties but I was misinformed by my own reading. That is why I had marked it unanswers. – Brad Semrad Feb 03 '12 at 14:47