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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With