13

C# では、特定のドライブがハード ドライブ、ネットワーク ドライブ、CDRom、またはフロッピーであることをどのように検出しますか?

4

3 に答える 3

18

メソッド GetDrives() は、System.IO.DriveType の列挙に対応するプロパティ DriveType を持つ DriveInfo クラスを返します。

public enum DriveType
{
    Unknown,         // The type of drive is unknown.  
    NoRootDirectory, // The drive does not have a root directory.  
    Removable,       // The drive is a removable storage device, 
                     //    such as a floppy disk drive or a USB flash drive.  
    Fixed,           // The drive is a fixed disk.  
    Network,         // The drive is a network drive.  
    CDRom,           // The drive is an optical disc device, such as a CD 
                     // or DVD-ROM.  
    Ram              // The drive is a RAM disk.   
}

すべてのドライブの情報を表示する、MSDN からのわずかに調整された例を次に示します。

    DriveInfo[] allDrives = DriveInfo.GetDrives();
    foreach (DriveInfo d in allDrives)
    {
        Console.WriteLine("Drive {0}, Type {1}", d.Name, d.DriveType);
    }
于 2008-09-29T14:09:34.500 に答える
4

DriveInfo.DriveTypeはあなたのために働くはずです。

DriveInfo[] allDrives = DriveInfo.GetDrives();

foreach (DriveInfo d in allDrives)
{
    Console.WriteLine("Drive {0}", d.Name);
    Console.WriteLine("  File type: {0}", d.DriveType);
}
于 2008-09-29T13:57:33.357 に答える
3

System.IO.DriveInfoクラスと DriveType プロパティを確認してください。

于 2008-09-29T13:57:56.383 に答える