Use of System.IO.DriveInfo class in Windows application using C#

Tuesday, April 14, 2009 |

I came across one task recently which needs interaction with windows drive. Today I finished it and thought to share one small part of that script with you. This script will simply find out all the available drive in your windows system and display its information about drive letter, drive type, free available space, format of drive. I have used C# windows application in my example so simply create one windows application, draw one button and one label on your windows form.

Once you prepare with your application, have a look at below given code which suppose to be placed in button1’s click event.

label1.Text = "";

foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())


if (drive.DriveType.ToString().ToLower() == "fixed" drive.DriveType.ToString().ToLower() == "removable")

label1.Text = label1.Text + drive.Name + "==>" + drive.DriveType + "==>" + drive.DriveFormat + "==>" + drive.AvailableFreeSpace + "\n";


label1.Text = label1.Text + drive.Name + "==>" + drive.DriveType + "==>0==>0\n";


So here you finished your small yet useful script.

Happy Programming!!!!

Reference: Ritesh Shah
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of