2011-06-17 21 views
3

ファイルの名前を取得するためにxmlを抽出し、これらのファイルをUSBドライブにコピーする必要があるファイルを作成しています。私がこれを行うことができる最初の2つのステップ。しかし、質問は次のとおりです。C#USBドライブの存在を確認する

  1. どのように私はUSBドライブ
  2. がある場合、それがどのドライブを検出検出することができます。

ありがとう! DriveType.Removeableプロパティ ため

+1

[私はどのようにしてUSBドライブ文字を検出できますか?](http://stackoverflow.com/questions/1273872/how-do-i-detect-a-usb-drive -letter-from-ac-application) –

+0

あなたはウイルスに感染していますか? –

答えて

1

チェックDriveInfo.GetDrives()は、このコードは、他の方向に行くFullName

5

チェックし、それは「私は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); 
       } 
      } 
     } 
+0

これは優れています。ありがとうございました! –

関連する問題