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 with 3 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 :(


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 >>
Sponsors
Discover Geekpedia

Other Resources