So, I am trying to get a query working that finds a certain flash drive attached to my computer and selects it's DriveInfo object. I am having trouble because on my system when I call the VolumeLabel property of one of my DriveInfo objects it throws an exception (IOException) because the drive is not ready to write. For some reason I have a H:\ drive which is erroring out on me, does not appear in Windows explorer, or it could be due to some other software installed on my system. Regaurdless I need to skip over any drive that throws an exception like this. Here is the code:
var exfil = from drive in DriveInfo.GetDrives() where drive.DriveType == DriveType.Removable where drive.VolumeLabel == "EXFIL" select drive;
I also tried looking at the Expression.TryCatch method, but I don't know how to get it working. After I get the IEnumerable object I will simply select the first drive I find, which I am sure will be the right one since nobody will name their drive what I name mine.
Edited 2 Years Ago by overwraith: More clairity