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/

posted @ 2011-09-05 19:40  jyshi  阅读(2156)  评论(0编辑  收藏  举报
无觅相关文章插件,快速提升流量