You can use the System.IO.DriveInfo class in C# to get information about available drives and their properties such as
name, type, format, total size, and
freespace.
Example: List All Drives and Their Free Space
using System;
using System.IO;
class Program
{
static void Main()
{
DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo drive in allDrives)
{
Console.WriteLine($"Drive: {drive.Name}");
if (drive.IsReady)
{
Console.WriteLine($" Drive type: {drive.DriveType}");
Console.WriteLine($" Volume label: {drive.VolumeLabel}");
Console.WriteLine($" File system: {drive.DriveFormat}");
Console.WriteLine($" Available space to current user: {drive.AvailableFreeSpace / 1024 / 1024} MB");
Console.WriteLine($" Total available space: {drive.TotalFreeSpace / 1024 / 1024} MB");
Console.WriteLine($" Total size of drive: {drive.TotalSize / 1024 / 1024} MB");
}
else
{
Console.WriteLine(" Drive not ready.");
}
Console.WriteLine();
}
}
}
🔍 Output Sample (Windows)
Drive: C:\
Drive type: Fixed
Volume label: System
File system: NTFS
Available space to current user: 128736 MB
Total available space: 128736 MB
Total size of drive: 249856 MB
Drive: D:\
Drive not ready.
Useful Properties of DriveInfo
Property
Description
Name
Drive letter (e.g., C:\)
DriveType
Fixed, Removable, Network, etc.
IsReady
True if the drive is accessible
VolumeLabel
Name assigned to the drive
DriveFormat
File system type (NTFS, FAT32, etc.)
AvailableFreeSpace
Free space available to current user
TotalFreeSpace
Total free space on the drive
TotalSize
Total capacity of the drive
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
You can use the
System.IO.DriveInfoclass in C# to get information about available drives and their properties such as name, type, format, total size, and free space.Example: List All Drives and Their Free Space
🔍 Output Sample (Windows)
Useful Properties of
DriveInfoNameC:\)DriveTypeIsReadyVolumeLabelDriveFormatAvailableFreeSpaceTotalFreeSpaceTotalSize