0

I have tried these 2 different function but it doesn't work as expected. How to determine if drive is external drive <- the method provided on this also returns true for usb thumbdrive. But, i am looking specifically for external hard drive.

       DriveInfo[] allDrives = DriveInfo.GetDrives();
       foreach (DriveInfo d in allDrives)     
       if (d.DriveType == DriveType.Fixed && d.Name != "C:" + @"\"){}
posh
  • 31
  • 7
  • In your estimation, what determines whether any particular USB flash-based mass storage is a "hard drive" or a "thumb drive"? For the OS, the difference is partitioning. – Ben Voigt Mar 06 '18 at 17:17

1 Answers1

-2

The DriveType enum also has a Removable property:

System.IO.DriveType driveType = drive.DriveType;
switch (driveType)
{
    case System.IO.DriveType.CDRom:
        break;
    case System.IO.DriveType.Fixed:
        // Local Drive
        break;
    case System.IO.DriveType.Network:
        // Mapped Drive
        break;
    case System.IO.DriveType.NoRootDirectory:
        break;
    case System.IO.DriveType.Ram:
        break;
    case System.IO.DriveType.Removable:
        // Usually a USB Drive
        break;
    case System.IO.DriveType.Unknown:
        break;
}

You can query for the type.

JazzmanJim
  • 97
  • 1
  • 5