Results 1 to 3 of 3

Thread: Hard Drive Info

  1. #1

    Thread Starter
    Member
    Join Date
    May 1999
    Location
    San Jose, CA, USA
    Posts
    43

    Post

    How do I get the amount of free space on a certain hard drive of a system?

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use the GetDiskFreeSpace API, eg.
    Code:
    Private Declare Function GetDiskFreeSpace Lib "kernel32" Alias "GetDiskFreeSpaceA" (ByVal lpRootPathName As String, lpSectorsPerCluster As Long, lpBytesPerSector As Long, lpNumberOfFreeClusters As Long, lpTotalNumberOfClusters As Long) As Long
    
    Private Sub Command1_Click()
        Dim lSPC As Long, lBPS As Long, lNFC As Long, lTNC As Long
        Call GetDiskFreeSpace(ByVal "C:\", lSPC, lBPS, lNFC, lTNC)
        Caption = Format(CCur(lSPC * lBPS * lNFC), "##,##")
    End Sub
    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]

    [This message has been edited by Aaron Young (edited 12-04-1999).]

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744

    Post

    Aaron is right but GetDiskFreeSpace API can handle hard drives up to 2GB. To get the free space for hard drives over 2GB use GetDiskFreeSpaceEx instead.

    Code:
    Declare Function GetDiskFreeSpaceEx Lib "kernel32" Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, lpFreeBytesAvailableToCaller As Currency, lpTotalNumberOfBytes As Currency, lpTotalNumberOfFreeBytes As Currency) As Long
    
    Private Function GetFreeSpace(pDrive As String) As String
        Dim curTotalBytes As Currency
        Dim curFreeBytesToCaller As Currency
        Dim curTotalFreeBytes As Currency
        
        Call GetDiskFreeSpaceEx(pDrive, curFreeBytesToCaller, curTotalBytes, curTotalFreeBytes)
        GetFreeSpace = Format$(curTotalFreeBytes * 10000, "###,###,###,##0")
    End Function
    Example:


    MsgBox "Free space on drive C: is: " & GetFreeSpace("C:")


    ------------------

    Serge

    Software Developer
    [email protected]
    [email protected]
    ICQ#: 51055819


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width