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
ManagementObjectSearcherusing it to query the disk drives that are USB, then obtain the corresponding unit letter and return only theDriveInfoof whichRootDirectory.Nameis contained in the result set.Using LINQ Query Expressions:
Using LINQ Extension Methods:
Using foreach:
To use
ManagementObjectyou need to add reference toSystem.ManagementI haven't tested it well because now I don't have any SD card, but I hope it helps