首页 > 其他 > 详细

C# 获取磁盘容量

时间:2014-06-27 22:56:49      阅读:436      评论:0      收藏:0      [点我收藏+]
原文: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/

C# 获取磁盘容量,布布扣,bubuko.com

C# 获取磁盘容量

原文:http://www.cnblogs.com/lonelyxmas/p/3811054.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!