life's a journey not a destination

Lấy danh sách các phân vùng ổ cứng, đĩa mạng, usb và cd rom trên máy dùng C#

Leave a comment

using System;
using System.IO;

namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
                DriveInfo[] drives = DriveInfo.GetDrives();
                foreach (DriveInfo di in drives)
                    if (di.IsReady)
                        Console.WriteLine("Volume label: {0} ", di.VolumeLabel);
                        Console.WriteLine("Drive Type: {0} ", di.DriveType);
                        Console.WriteLine("Free space: {0} bytes ", di.TotalFreeSpace);
                        Console.WriteLine("Drive Size: {0} bytes \n", di.TotalSize);
            catch (Exception ex)
                // handle ex


Author: dinhnn

Senior software developer, a technical leader. You can be reached at via email to dinhnguyenngoc@gmail.com, via my blog at dinhnguyenngoc.wordpress.com, and on Twitter @dinhnguyenngoc.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s