How to Find Attached Drives?

  • Thread starter Thread starter Talal Itani
  • Start date Start date
T

Talal Itani

Hello,

I am writing my first C# program. Things are going well. My program needs
to find all the drives that are attached to the PC, with the attributes of
each drive. How can this be done? This is for XP. Thanks.

T.I.
 
Talal,

You can use the static GetDrives method on the DriveInfo class in the
System.IO namespace to get information about the drives on your system.
 
Talal Itani said:
Hello,

I am writing my first C# program. Things are going well. My program
needs to find all the drives that are attached to the PC, with the
attributes of each drive. How can this be done? This is for XP. Thanks.

T.I.

Something like this.

static void Main( string[] args )
{
// gather an array of drive names
string[] drives = Directory.GetLogicalDrives();

// iterate through them and get the drive information for each.
foreach (string drv in drives)
{
DriveInfo di = new DriveInfo(drv);
Console.WriteLine("Drive " + drv + " is " + di.DriveType); //
Theres more that just the type in this class.
}

Console.WriteLine("\nPress any key to continue...");
while (!Console.KeyAvailable);
}

Read through the help files on Directory and DriveInfo.

Mark
 

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