Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to list logical drives without mapped drives

Tags:

c#

I would like to populate a combo box with a list of logical drives but I would like to exclude any mapped drives. The code below gives me a list of all logical drives without any filtering.

comboBox.Items.AddRange(Environment.GetLogicalDrives());

Is there a method available that can help you determine between physical drives and mapped drives?

like image 878
robmo Avatar asked Jan 31 '13 16:01

robmo


1 Answers

You could use the DriveInfo class

    DriveInfo[] allDrives = DriveInfo.GetDrives();
    foreach (DriveInfo d in allDrives)
    {
        Console.WriteLine("Drive {0}", d.Name);
        Console.WriteLine("  File type: {0}", d.DriveType);
        if(d.DriveType != DriveType.Network)
        {
            comboBox.Items.Add(d.Name);
        }
    }

exclude the drive when the property DriveType is Network

like image 97
Steve Avatar answered Oct 30 '22 01:10

Steve