Benjol
Benjol

Reputation: 66587

Get local drives without hitting floppy

I'm looking for a way to scan for hard disks without incurring the 'floppy tax' of the system attempting to read the floppy drive to see if there's a disk in there.

Important: I know how to use DriveInfo.GetDrives to get just hard disks, but that involves filtering after the list has been created. What I want to do is filter before, if it's possible.

Upvotes: 2

Views: 1172

Answers (3)

Ali Besharati
Ali Besharati

Reputation: 1046

The CD Drive And floppy Drive is not ready so you can try this :

foreach (var dr in DriveInfo.GetDrives())
{
    if (dr.IsReady == true)
    {
        Console.WriteLine(string.Format("name : {0}   type : {1}", dr, dr.DriveType));
    }
}

Upvotes: 1

puikos
puikos

Reputation: 300

You can try this :

ConnectionOptions opts = new ConnectionOptions();
ManagementScope scope = new ManagementScope(@"\\.\root\cimv2", opts);
SelectQuery diskQuery = new SelectQuery("SELECT * FROM Win32_LogicalDisk WHERE (MediaType != 0 AND MediaType = 11 OR MediaType = 12)");

ManagementObjectSearcher searcher = new ManagementObjectSearcher(diskQuery);
ManagementObjectCollection diskObjColl = searcher.Get();

Media types 11 and 12 are not floppy. You can find full documentation here : http://msdn.microsoft.com/en-us/library/windows/desktop/aa394173%28v=vs.85%29.aspx

Upvotes: 2

Martin Stam
Martin Stam

Reputation: 84

Not as such... Drive info simply has no functions to filter or exclude any types of drives during a getDrives call.

But maybe there's another way. (This is untested but maybe an idea: ) If you're simply looking for the availability of specific drives, you can instantiate the DriveInfo class with the name of a specific drive and see if that works?

Upvotes: 1

Related Questions