C#判断磁盘剩余空间是否足够

2021-03-04 12:26

阅读:584

标签:logic   save   result   get   lse   select   ica   else   tin   

public static bool GetDiskInfo()
        {
            if (false == strCheckFreeSpace.Equals("1"))
                return true;
            try
            {
                //获得盘符HARDDISK
                var index = strSaveFolder.Trim().IndexOf(‘:‘);
                var HARDDISK = strSaveFolder.Trim().Substring(0, index + 1);

                SelectQuery selectQuery = new SelectQuery("select * from win32_logicaldisk");
                ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);
                ManagementObjectCollection diskcollection = searcher.Get();
                if (diskcollection != null && diskcollection.Count > 0)
                {
                    foreach (ManagementObject item in searcher.Get())
                    {
                        int nType = Convert.ToInt32(item["DriveType"]);
                        if (nType != Convert.ToInt32(DriveType.Fixed))
                        {
                            continue;
                        }
                        else
                        {
                            if (item["DeviceID"].ToString().ToUpper() == HARDDISK)
                            {
                                double bytes = Convert.ToDouble(item["FreeSpace"]);

                                var result = bytes / Math.Pow(1024, 3);

                                if (result 

  

C#判断磁盘剩余空间是否足够

标签:logic   save   result   get   lse   select   ica   else   tin   

原文地址:https://www.cnblogs.com/zmy2020/p/12935118.html


评论


亲,登录后才可以留言!