Find a device connected to a usb-port


I have device connected to a usb-port, that you see in the picture.
I have some code to detect the name of the device but its not working
The code doesn't detect the device.

I get an IOExecption with a message:
"Device not ready"

Who knows the answer and is willing to help me?

Peter Kiers
private void button1_Click(object sender, EventArgs e)
           foreach (System.IO.DriveInfo di in System.IO.DriveInfo.GetDrives())
              if (di.VolumeLabel.Equals("SmartPix", StringComparison.InvariantCultureIgnoreCase))
                  MessageBox.Show("Device found");
                  if (System.IO.Directory.GetFiles(@"\REPORT\XML", "G*.xml").Length > 0)
                      MessageBox.Show("File found");

Open in new window

Peter KiersOperatorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You are scanning all logical drives include CD-ROM, DVD-ROM etc..
In order to exclude it you can just use

using System.Linq;

Open in new window

IEnumerable<DriveInfo> drives = DriveInfo.GetDrives().Where(d => d.DriveType != DriveType.CDRom);

Open in new window

Also you can exclude other unwanted  drive types that are in DriveType list.
Peter KiersOperatorAuthor Commented:
Can you give me a little example how to find the device called SmartPix.

DriveInfo drive = DriveInfo.GetDrives().Single(d => d.DriveType == DriveType.Removable && d.VolumeLabel == "SmartPix");

            Console.WriteLine(drive.VolumeLabel ?? "Drive is not found");


Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Peter KiersOperatorAuthor Commented:
Great, wish you good luck ans thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.