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

<<  May 2024  >>
MoTuWeThFrSaSu
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

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