Detecting CD drive letter in C#

  • Thread starter Thread starter yellowblueyellow
  • Start date Start date
Y

yellowblueyellow

Hey All,

I am using the following line of code to pick all logical drives on
the local machine:

string[] drives = Directory.GetLogicalDrives();

using the above code I can get output in the form of C:\, D:\, E:
\..etc

now I want to filter out the CD/DVD and FLOPPY drive... how do I do
this?

thanks
 
Hey All,

I am using the following line of code to pick all logical drives on
the local machine:

string[] drives = Directory.GetLogicalDrives();

using the above code I can get output in the form of C:\, D:\, E:
\..etc

now I want to filter out the CD/DVD and FLOPPY drive... how do I do
this?

System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();

foreach (System.IO.DriveInfo drive in drives)
{
if (drive.DriveType == System.IO.DriveType.CDRom)
Console.WriteLine(drive.Name);
}

Floppies will appear as DriveType.Removable, same as USB drives.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top