C # reading disk usage (total space available space)

Read disk usage

1、using System.IO.DriveInfo;

DriveInfo class to read the disk usage:

     //获取磁盘使用情况     
     public string GetDriverInfo()
        {
            string result="";
            foreach (DriveInfo drive in DriveInfo.GetDrives())
            {
                //判断是否是固定磁盘
                if (drive.DriveType == DriveType.Fixed)
                {
                    long total = drive.TotalSize / 1024 * 1024 * 1024;
                    long free = drive.TotalFreeSpace / 1024 * 1024 * 1024;
                    result += drive.Name + ": 总空间=" + total.ToString() + " G 剩余空间=" + free.ToString() + " G\r\n";
                }
            }
            return result;
        }

2 results:

Published 35 original articles · won praise 8 · views 20000 +

Guess you like

Origin blog.csdn.net/wenming111/article/details/103873643