leo leo - 11 months ago 63
C# Question

How do I retrieve disk information in C#?

I would like to access information on the logical drives on my computer using C#. How should I accomplish this? Thanks!

Answer Source

For most information, you can use the DriveInfo class.

using System;
using System.IO;

class Info {
    public static void Main() {
        DriveInfo[] drives = DriveInfo.GetDrives();
        foreach (DriveInfo drive in drives) {
            //There are more attributes you can use.
            //Check the MSDN link for a complete example.
            if (drive.IsReady) Console.WriteLine(drive.TotalSize);