Displaying drive information

Mar 5 2010 10:35 PM

I am new to C#. I am not able to retreive information about all drives in my laptop. I used following code.
    using System;
    using System.IO;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
   
    namespace IOEx
    {
        class DriveList
        {
            static void Main()
            {
                foreach (DriveInfo drvInfo in DriveInfo.GetDrives())
                {
                    try
                    {
                        //if (drvInfo.IsReady)
                        {
                            Console.WriteLine("Drive {0} ({1}), free space  {2:#,#} GB Total space ({3: #,#}) GB", drvInfo.Name, drvInfo.VolumeLabel, drvInfo.TotalFreeSpace, drvInfo.TotalSize);
                        }
   
   
                    }
                    catch(Exception ex)
                    {
                        Console.WriteLine("Application generated exception : "+ex.Message);
                    }
                    Console.ReadKey();
                }
            }
        }
    }
the laptop has hard disk with two partitions and a CD rom. The output displayed shows information about C drive only that too considering entire physical drive. program do not detect CD rom. Can somebody explain.
 

Answers (4)