首页 > 代码库 > C# 获取磁盘容量
C# 获取磁盘容量
原文:C# 获取磁盘容量
/// 获取指定驱动器的空间总大小(单位为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; } } 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; } }
其它相关:
转自:http://www.cnblogs.com/jyshi/
<script type="text/javascript">// </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// </script><script type="text/javascript">// </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js">// </script>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。