2
すべてのドライブを調べ、「DOM WORK」という名前のリムーバブルディスクを見つけようとするプログラムを作成しようとしていますドライブ名(E :)のようにして、それを印刷します。私は実行可能ファイルとしてプログラムをビルドして、動作しませんでした管理者権限、でそれを実行しているしようとしているDriveInfo.GetDrives()を使用しているときに「デバイスが準備ができていません」というエラーが表示される
Unhandled Exception: System.IO.IOException: The device is not ready.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.__Error.WinIODriveError(String driveName, Int32 errorCode)
at System.IO.DriveInfo.get_VolumeLabel()
at WorkSync.Program.Main(String[] args) in d:\dominic\documents\visual studio 2015\Projects\WorkSync\WorkSync\Program.cs:line 19
:残念ながら、私はこのエラーメッセージが表示されます。あなたがドライブがDriveInfo.IsReadyプロパティを使用して、実際にアクセス可能であることを確認する必要があり
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WorkSync
{
class Program
{
static void Main(string[] args)
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
string memStickName = "";
foreach(DriveInfo drive in allDrives)
{
Console.WriteLine(drive.VolumeLabel);
if (drive.VolumeLabel == "DOM WORK" && drive.DriveType.ToString() == "removable")
{
memStickName = drive.Name;
break;
}
}
Console.WriteLine(memStickName);
}
}
}