Ge Total Free Space on a Drive (In KB - Tb)

by ssi 28. December 2015 10:56
private static long GetTotalFreeSpace(string sDriveName)
       {
           long nRet = -1;
           foreach (DriveInfo drive in DriveInfo.GetDrives())
           {
               if (drive.IsReady && drive.Name == sDriveName)
               {
                   nRet = drive.TotalFreeSpace;
               }
           }
           return nRet;
       }
 
       private static long GetTotalFreeSpace(string sDriveName, string sUnits)
       {
           long nDenominator = 1;
           switch (sUnits)
           {
               case "K":
                   nDenominator = 1024;
                   break;
               case "M":
                   nDenominator = 1048576;
                   break;
               case "G":
                   nDenominator = 1073741824;
                   break;
               case "T":
                   nDenominator = 1099511627776;
                   break;
               default:
                   break;
           }
 
 
           long nRet = -1;
           foreach (DriveInfo drive in DriveInfo.GetDrives())
           {
               if (drive.IsReady && drive.Name == sDriveName)
               {
                   nRet =(longclsCommonStatics.ZeroDouble ((double) drive.TotalFreeSpace, (double)nDenominator) ;
               }
           }
           return nRet;
       }

Tags: , ,

CSharp | SQL

Calendar

<<  July 2025  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

RecentComments

None

Development Team @ Shelbysys

We develop custom database applications for our clients. Our development tool of choice is MS Visual Studio. 

Quotations

"The distance between insanity and genius is measured only by success."
Bruce Feirstein