ファイルの名前を取得するためにxmlを抽出し、これらのファイルをUSBドライブにコピーする必要があるファイルを作成しています。私がこれを行うことができる最初の2つのステップ。しかし、質問は次のとおりです。C#USBドライブの存在を確認する
- どのように私はUSBドライブ
- がある場合、それがどのドライブを検出検出することができます。
ありがとう! DriveType.Removeable
プロパティ ため
ファイルの名前を取得するためにxmlを抽出し、これらのファイルをUSBドライブにコピーする必要があるファイルを作成しています。私がこれを行うことができる最初の2つのステップ。しかし、質問は次のとおりです。C#USBドライブの存在を確認する
ありがとう! DriveType.Removeable
プロパティ ため
チェックDriveInfo.GetDrives()
は、このコードは、他の方向に行くFullName
チェックし、それは「私はUSBドライブを見つけるのですか」という質問に処理します。
using System.IO;
//を。 。 。
foreach (DriveInfo removableDrive in DriveInfo.GetDrives().Where(
d => d.DriveType == DriveType.Removable && d.IsReady))
{
DirectoryInfo rootDirectory = removableDrive.RootDirectory;
string monitoredDirectory = Path.Combine(rootDirectory.FullName, DIRECTORY_TO_MONITOR);
string localDestDirectory = Path.Combine(destDirectory, removableDrive.VolumeLabel);
if (!Directory.Exists(localDestDirectory))
Directory.CreateDirectory(localDestDirectory);
if (Directory.Exists(monitoredDirectory))
{
foreach (string file in Directory.GetFiles(monitoredDirectory))
{
File.Copy(file, Path.Combine(localDestDirectory, Path.GetFileName(file)), true);
}
}
}
これは優れています。ありがとうございました! –
[私はどのようにしてUSBドライブ文字を検出できますか?](http://stackoverflow.com/questions/1273872/how-do-i-detect-a-usb-drive -letter-from-ac-application) –
あなたはウイルスに感染していますか? –