我有这段代码:
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);
}
}
}
我有个问题。它首先尝试软盘驱动器的代码,并且因为其中没有软盘,所以它抛出了错误我该The device is not ready.
如何防止呢?