两种取得硬盘剩余空间方法

取出来的单位是B:)

    [DllImport( " kernel32.dll " )]
    
private   static   extern   bool  GetDiskFreeSpaceEx(
        
string  lpDirectoryName,  out   ulong  lpFreeBytesAvailable,  out   ulong  lpTotalNumberOfBytes,  out   ulong  lpTotalNumberOfFreeBytes);

    
///  
    
///  取得磁盘剩余空间
    
///  

    
///   驱动器名
    
///   剩余空间
     private   static   ulong  GetFreeSpace( string  driveDirectoryName)
    {
        
ulong  freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes;
        
if  ( ! driveDirectoryName.EndsWith( " :\\ " ))
        {
            driveDirectoryName 
+=   " :\\ " ;
        }
        GetDiskFreeSpaceEx(driveDirectoryName, 
out  freeBytesAvailable,  out  totalNumberOfBytes,  out  totalNumberOfFreeBytes);
        
return  freeBytesAvailable;
    }

     ///  
    
///  取得磁盘剩余空间
    
///  

    
///   驱动器名
    
///   剩余空间
     private   static   ulong  GetFreeSpace( string  driveDirectoryName)
    {
        
ulong  freefreeBytesAvailable  =   0 ;

        DriveInfo drive 
=   new  DriveInfo(driveDirectoryName);

        freefreeBytesAvailable 
=  ( ulong )drive.AvailableFreeSpace;

        
return  freefreeBytesAvailable;
    }

转载于:https://www.cnblogs.com/luoboqingcai/archive/2006/06/13/424763.html

你可能感兴趣的:(两种取得硬盘剩余空间方法)