USB device Set Attribute in C#
- by p19lord
I have this bit of code:
DriveInfo[] myDrives = DriveInfo.GetDrives();
foreach (DriveInfo myDrive in myDrives)
{
if (myDrive.DriveType == DriveType.Removable)
{
string path = Convert.ToString(myDrive.RootDirectory);
DirectoryInfo mydir = new DirectoryInfo(path);
String[] dirs = new string[] {Convert.ToString(mydir.GetDirectories())};
String[] files = new string[] {Convert.ToString(mydir.GetFiles())};
foreach (var file in files)
{
File.SetAttributes(file, ~FileAttributes.Hidden);
File.SetAttributes(file, ~FileAttributes.ReadOnly);
}
foreach (var dir in dirs)
{
File.SetAttributes(dir, ~FileAttributes.Hidden);
File.SetAttributes(dir, ~FileAttributes.ReadOnly);
}
}
}
I have a problem. It is trying the code for Floppy Disk drive first which and because no Floppy disk in it, it threw the error The device is not ready. How can I prevent that?