By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,353 Members | 1,237 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,353 IT Pros & Developers. It's quick & easy.

Detecting CD drive letter in C#

P: n/a
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

Jul 12 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
use p-invoke to call GetDriveType
see http://msdn.microsoft.com/msdnmag/issues/04/01/CQA/
--
Sheng Jiang
Microsoft MVP in VC++
<ye**************@gmail.comwrote in message
news:11**********************@n60g2000hse.googlegr oups.com...
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

Jul 12 '07 #2

P: n/a
ye**************@gmail.com wrote:
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.
--
Tom Porterfield
Jul 12 '07 #3

P: n/a
Hi,

To get the drive list better to use the:
DriveInfo[] dr = System.IO.DriveInfo.GetDrives();

And to detect its type Just:
dr[<index>].DriveType

Regards, Alex Meleta
[TechBlog] http://devkids.blogspot.com
Directory

Jul 12 '07 #4

P: n/a
awesome .. thanks a bunch guys

On Jul 12, 1:52 pm, Alex Meleta <amel...@gmail.comwrote:
Hi,

To get the drive list better to use the:
DriveInfo[] dr = System.IO.DriveInfo.GetDrives();

And to detect its type Just:
dr[<index>].DriveType

Regards, Alex Meleta
[TechBlog]http://devkids.blogspot.com
Directory- Hide quoted text -

- Show quoted text -

Jul 12 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.