Windows 7 platform, C#
I use the following statement to list all drives:
DriveInfo[] drives = DriveInfo.GetDrives();
then I can use DriveType to find out all those removable disks:
foreach (var drive in drives)
{
if(drive.DriveType == DriveType.Removable)
yield return drive;
}
now my problem is, SD-card disk and USB flashdisk shared same driveType: Removable, so how can i only find USB flashdisk out?
thanks!
You can take advantage of
ManagementObjectSearcher
using it to query the disk drives that are USB, then obtain the corresponding unit letter and return only theDriveInfo
of whichRootDirectory.Name
is contained in the result set.Using LINQ Query Expressions:
Using LINQ Extension Methods:
Using foreach:
To use
ManagementObject
you need to add reference toSystem.Management
I haven't tested it well because now I don't have any SD card, but I hope it helps