zoukankan      html  css  js  c++  java
  • C#获取硬盘空间信息

            ///  <summary> 
            /// 获取指定驱动器的空间总大小(单位为B) 
            ///  </summary> 
            ///  <param name="str_HardDiskName">只需输入代表驱动器的字母即可 </param> 
            ///  <returns> </returns> 
            public static long GetHardDiskSpace(string str_HardDiskName) 
            { 
                long totalSize= new long(); 
                str_HardDiskName=str_HardDiskName +":\"; 
                System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); 
                foreach (System.IO.DriveInfo drive in drives) 
                { 
                    if (drive.Name == str_HardDiskName) 
                    {
                        totalSize = drive.TotalSize / (1024 * 1024 * 1024); 
                    } 
                } 
                return totalSize; 
            }
    
            ///  <summary> 
            /// 获取指定驱动器的剩余空间总大小(单位为B) 
            ///  </summary> 
            ///  <param name="str_HardDiskName">只需输入代表驱动器的字母即可 </param> 
            ///  <returns> </returns> 
            public static long GetHardDiskFreeSpace(string str_HardDiskName) 
            { 
                long freeSpace = new long(); 
                str_HardDiskName = str_HardDiskName + ":\"; 
                System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives(); 
                foreach (System.IO.DriveInfo drive in drives) 
                { 
                    if (drive.Name == str_HardDiskName) 
                    {
                        freeSpace = drive.TotalFreeSpace / (1024 * 1024 * 1024); 
                    } 
                } 
                return freeSpace; 
            }
  • 相关阅读:
    html input在标签内设置禁止输入空格
    JS判断json是否为空
    python常见问题集锦
    Node.js入门教程合集
    Vue入门教程合集
    将博客搬至CSDN
    Python 使用PyInstaller打包发布
    VSCode开发Python
    Python 验证码解析
    IntelliJ IDEA常见问题及使用技巧(持续更新)
  • 原文地址:https://www.cnblogs.com/dinotang/p/3272172.html
Copyright © 2011-2022 走看看