Geekpedia Tutorials Home

Building a C# Chat Client and Server

Building a C# Chat Client and ServerA step by step tutorial teaching you how to create your own chat client and chat server easily in C#, for local networks or the Internet.

in C# Programming Tutorials

Getting Hard Drive Information

Getting Hard Drive InformationA C# tutorial showing you how to make use of WMI to extract information on disk drives, such as model, capacity, sectors and serial number.

in C# Programming Tutorials

UPS Shipping Calculator

UPS Shipping CalculatorThis tutorial will teach you how to calculate the shipping cost based on the weight, height, length and depth of the box, the distance and the UPS service type.

in PHP Programming Tutorials

Create Your Own Rich Text Editor

Create Your Own Rich Text EditorCreating a Rich Text Editor using JavaScript is easier to do than you might think, thanks to the support of modern browsers; this tutorial will walk you through it.

in JavaScript Programming Tutorials
Search
Tutorials
Programming Tutorials
IT Jobs
From CareerBuilder

Retrieve a list of disk drives using C#

This code retrieves a list of drives, stores it into an array of strings, and then loops through it to display the drives.

On Thursday, October 18th 2007 at 08:09 PM
By Andrew Pociu (View Profile)
*****   (Rated 4.3 with 4 votes)
Contextual Ads
More C# Resources
Advertisement
  1. // Store the list of drives into an array of string
  2. string[] DriveList = Environment.GetLogicalDrives();
  3. // Loop through the array
  4. for (int i = 0; i < DriveList.Length; i++)
  5. {
  6.     // Show each drive
  7.     MessageBox.Show(DriveList[i]);
  8. }
Digg Digg It!     Del.icio.us Del.icio.us     Reddit Reddit     StumbleUpon StumbleIt     Newsvine Newsvine     Furl Furl     BlinkList BlinkList

Rate Rate this code snippet
Comment Current Comments
by tony on Monday, November 24th 2008 at 01:02 AM

Excellent

by TaToosh on Friday, November 28th 2008 at 03:11 PM

how to get only local hard drives, no cd/dvd or mapped network ones?

by Reelix on Thursday, July 30th 2009 at 02:52 AM

static void Main(string[] args)
{

Console.Title = "Storm Disk Space Mailer.";
// Store the list of drives into an array of string
string[] DriveList = Environment.GetLogicalDrives();
// Loop through the array
for (int i = 0; i < DriveList.Length; i )
{
// Show each drive
getSize(DriveList[i].Replace(":\\", ""));
}
Console.WriteLine("Listing Complete - Press enter to close.");
Console.ReadLine();
}

public static void getSize(string drive)
{
ManagementObject diskSize = new ManagementObject("win32_logicaldisk.deviceid=\"" drive ":\"");

diskSize.Get();
double GB = Convert.ToDouble(diskSize["FreeSpace"]);
GB = ((((GB / 1024) / 1024) / 1024));
string GBS = GB.ToString();
try
{
GBS = GBS.Substring(0, (GBS.IndexOf(".") 3));
}
catch
{
// Do Nothing
}
string DriveType = diskSize["DriveType"].ToString();
switch (DriveType)
{
case "0":
DriveType = "Unknown";
break;
case "1":
DriveType = "No Root Directory";
break;
case "2":
DriveType = "Removable Disk";
break;
case "3":
DriveType = "Local Disk";
break;
case "4":
DriveType = "Network Drive";
break;
case "5":
DriveType = "Compact Disc";
break;
case "6":
DriveType = "RAM Disk";
break;
default:
DriveType = "Unknown";
break;
}
if (DriveType == "Compact Disc")
{
Console.WriteLine("Drive: " drive " is a CD/DVD Drive - Skipped...");
}
else
{
Console.WriteLine("Drive: " drive " is a " DriveType " with " GBS.ToString() " GB free space.");
}
}

by Reelix on Thursday, July 30th 2009 at 02:52 AM

static void Main(string[] args)
{

Console.Title = "Storm Disk Space Mailer.";
// Store the list of drives into an array of string
string[] DriveList = Environment.GetLogicalDrives();
// Loop through the array
for (int i = 0; i < DriveList.Length; i )
{
// Show each drive
getSize(DriveList[i].Replace(":\\", ""));
}
Console.WriteLine("Listing Complete - Press enter to close.");
Console.ReadLine();
}

public static void getSize(string drive)
{
ManagementObject diskSize = new ManagementObject("win32_logicaldisk.deviceid=\"" drive ":\"");

diskSize.Get();
double GB = Convert.ToDouble(diskSize["FreeSpace"]);
GB = ((((GB / 1024) / 1024) / 1024));
string GBS = GB.ToString();
try
{
GBS = GBS.Substring(0, (GBS.IndexOf(".") 3));
}
catch
{
// Do Nothing
}
string DriveType = diskSize["DriveType"].ToString();
switch (DriveType)
{
case "0":
DriveType = "Unknown";
break;
case "1":
DriveType = "No Root Directory";
break;
case "2":
DriveType = "Removable Disk";
break;
case "3":
DriveType = "Local Disk";
break;
case "4":
DriveType = "Network Drive";
break;
case "5":
DriveType = "Compact Disc";
break;
case "6":
DriveType = "RAM Disk";
break;
default:
DriveType = "Unknown";
break;
}
if (DriveType == "Compact Disc")
{
Console.WriteLine("Drive: " drive " is a CD/DVD Drive - Skipped...");
}
else
{
Console.WriteLine("Drive: " drive " is a " DriveType " with " GBS.ToString() " GB free space.");
}
}

by Reelix on Thursday, July 30th 2009 at 02:53 AM

Ewps, Double Post :(

by Mohsen on Tuesday, November 23rd 2010 at 05:42 AM

Disk Drive List

by love poems on Saturday, August 13th 2011 at 03:58 PM

Well I definitely liked reading it. This information provided by you is very constructive for correct planning.

by retirement wishes on Monday, August 15th 2011 at 04:23 AM

I do cerebrate the grouping are where lots of the fun was in. I act to hit a advancement await into my web log so you can knotted the entropy

by 0 interest on balance transfers on Wednesday, December 14th 2011 at 10:22 AM

Why don't you post your own solution Pavlo..... it would have sure taken less time than writing all that.

by Sarath on Thursday, May 17th 2012 at 05:45 AM

Can u tel me to find the directories of my server system .. Using its name.. Its Name is //Admin-Pc..
If U knw means please mail me

Sarathkumar.baap@gmail.com

by Sarath on Thursday, May 17th 2012 at 05:45 AM

Can u tel me to find the directories of my server system .. Using its name.. Its Name is //Admin-Pc..
If U knw means please mail me

Sarathkumar.baap@gmail.com

by dilip on Wednesday, August 1st 2012 at 12:58 AM

i have read this code,and now using this i can retrive local disc drive in my project..

by Reelix on Wednesday, August 1st 2012 at 10:28 AM

The e-mail post bumps 3 years later - Good gawd :|


Comment Comment on this tutorial
Name: Email:
Message:
Comment Related Source Code
There is no related code.

Comment Related Tutorials
There are no related tutorials.

Jobs C# Job Search
My skills include:

Enter a City:

Select a State:


Advanced Search >>
Ads

From the creators of Geekpedia, a revolutionary new coupon website!

BargainEZ has coupons codes, printable coupons, bargains and it is the leading source of Passbook coupons for iPhone and iPod touch devices.

Coupons
Discover Geekpedia
Other Resources