DESKTOP

Enumerate Drives

9/25/2010 3:16:17 PM
Problem : You want to get a list of all drives installed on the system.

Solution:
The DriveInfo class provides static methods to retrieve this information.

DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo info in drives)
{
Console.WriteLine("Name: {0} (RootDirectory: {1}",
info.Name, info.RootDirectory);
Console.WriteLine("DriveType: {0}", info.DriveType);
Console.WriteLine("IsReady: {0}", info.IsReady);
//you'll get an exception if you try to read some
//info when the drive isn't ready
if (info.IsReady)
{
Console.WriteLine("VolumeLabel: {0}", info.VolumeLabel);

Console.WriteLine("DriveFormat: {0}", info.DriveFormat);
Console.WriteLine("TotalSize: {0:N0}", info.TotalSize);
Console.WriteLine("TotalFreeSpace: {0:N0}", info.TotalFreeSpace);
Console.WriteLine("AvailableFreeSpace: {0:N0}",
info.AvailableFreeSpace);
}

Console.WriteLine();
}

This code produces the following output on my system (edited to show only unique drives):

Name: A:\ (RootDirectory: A:\)
DriveType: Removable
IsReady: False

Name: C:\ (RootDirectory: C:\)
DriveType: Fixed
IsReady: True
VolumeLabel:
DriveFormat: NTFS
TotalSize: 160,045,199,360
TotalFreeSpace: 81,141,878,784
AvailableFreeSpace: 81,141,878,784

Name: F:\ (RootDirectory: F:\)
DriveType: CDRom
IsReady: False

Name: H:\ (RootDirectory: H:\)
DriveType: Removable
IsReady: False

Other  
  •  Get File Security Description
  •  Combine Streams (Compress a File)
  •  Create, Read, and Write a Binary File
  •  Create, Read, and Write a Text File
  •  Opening a Local File from a Silverlight Application
  •  Navigating Architecture Changes in Windows Vista
  •  Getting Around Windows Vista
  •  Managing User Account Control and Elevation Prompts
  •  Supporting Computers Running Windows Vista
  •  Using System Support Tools in Vista
  •  Managing System Properties
  •  Introducing Automated Help And Support in Vista
  •  Working with the Automated Help System
  •  Installing and Maintaining Devices in Vista: The Essentials
  •  Getting Started with Device Manager
  •  Working with Device in Vista
  •  Managing Hardware in Vista
  •  Customizing Hardware Device Settings
  •  Managing Internet Time in Vista
  •  Optimizing Windows Vista Menus
  •  
    Top 10
    HP Envy X2 Review - A Hybrid Tablet-Laptop Failing To Bring Up A Complete Package (Part 2)
    HTC One SV Review – Not Just A Pretty Face (Part 3)
    HTC One SV Review – Not Just A Pretty Face (Part 2)
    HTC One SV Review – Not Just A Pretty Face (Part 1)
    Nokia Lumia 620 - The Cheapest Windows Phone 8
    CES 2013: What You Can Expect from The World’s Biggest Tech Show
    Googole vs. Apple (Part 2)
    Googole vs. Apple (Part 1)
    HP Envy X2 Review - A Hybrid Tablet-Laptop Failing To Bring Up A Complete Package (Part 1)
    Lenovo ThinkPad Tablet 2 Review (Part 3)
    Most View
    Nokia Lumia 920 - The World’s Most Innovative Smartphone
    Most Favorite Business Softwares – Feb 2013
    Nikon D600 - A Full-Frame Nikon For Your Full-Time Passion (Part 2)
    Linux Mint 10 : Tantalizing terminals
    ADO.NET Programming : Microsoft SQL Server CE (part 3) - Retrieving and Displaying Data
    Around London with iOS (Part 2)
    Jot Touch – The Magic Sketchpad
    Unboxing Apple products : Elegance in Design
    Backing Up the Exchange Server 2010 Environment : Supporting Backups with Documentation
    How Did We Get To Metro? (Part 2)
    Defensive Database Programming with SQL Server : Using TRY...CATCH blocks to Handle Errors
    HP Photosmart 5510 e-All-in-One Printer
    Compact Camera Shootout (Part 3) : Canon IXUS125 HS, Fujifilm FinePix F660 EXR, Nikon Coolpix S8200, Panasonic Lumix DMC-SZ1, Samsung WB150F
    Do You Really Need Security?
    SQL Server 2008 : Failover clustering - Clustering topologies and failover rules
    Maintaining and Optimizing Windows Vista Systems : Memory Usage and the Paging File
    Data Deduplication (Part 2)
    Implementing Client Access and Hub Transport Servers : Installing the Client Access Server
    Windows Server 2008 R2 : Manage Remote Desktop Services (part 3) - Configure Remote Desktop Web Access
    Tasmania - Ideal Destination For Landscape Photographers (Part 1)