Afla Free Space

Programare in Visual Basic 5/6
Visual Basic 5/6 programming

Afla Free Space

Post Number:#1  Postby freshmeat » 09 Nov 2012 11:38

Code: Select all

Public Type ULong ' Unsigned Long

    Byte1 As Byte
    Byte2 As Byte
    Byte3 As Byte
    Byte4 As Byte

End Type

Public Type LargeInt ' Large Integer

    LoDWord As ULong
    HiDWord As ULong
    LoDWord2 As ULong
    HiDWord2 As ULong

End Type

Public Declare Function GetDiskFreeSpaceEx _
               Lib "kernel32" _
               Alias "GetDiskFreeSpaceExA" (ByVal lpRootPathName As String, _
                                            FreeBytesAvailableToCaller As LargeInt, _
                                            TotalNumberOfBytes As LargeInt, _
                                            TotalNumberOfFreeBytes As LargeInt) As Long

Function GetFreeSpace(strPath As String) As Double

    Dim nFreeBytesToCaller As LargeInt

    Dim nTotalBytes        As LargeInt

    Dim nTotalFreeBytes    As LargeInt
 
    strPath = Trim(strPath)

    If Right(strPath, 1) <> "\" Then
        strPath = strPath & "\"
    End If
 
    If GetDiskFreeSpaceEx(strPath, nFreeBytesToCaller, nTotalBytes, nTotalFreeBytes) <> 0 Then
        GetFreeSpace = CULong(nFreeBytesToCaller.HiDWord.Byte1, nFreeBytesToCaller.HiDWord.Byte2, nFreeBytesToCaller.HiDWord.Byte3, nFreeBytesToCaller.HiDWord.Byte4) * 2 ^ 32 + CULong(nFreeBytesToCaller.LoDWord.Byte1, nFreeBytesToCaller.LoDWord.Byte2, nFreeBytesToCaller.LoDWord.Byte3, nFreeBytesToCaller.LoDWord.Byte4)
    End If

End Function

Function CULong(Byte1 As Byte, Byte2 As Byte, Byte3 As Byte, Byte4 As Byte) As Double
    CULong = Byte4 * 2 ^ 24 + Byte3 * 2 ^ 16 + Byte2 * 2 ^ 8 + Byte1
End Function
User avatar
freshmeat
Mediu
Mediu
Progress to next rank:
36%
 
Status: Offline
Posts: 68
Age: 31
Joined: 08 Nov 2012 10:24
Location: Romania

Invitations sent: 0
Referrals: 0
National Flag:
Romania
Local time: 20 Sep 2017 06:46
Has thanked: 10 times
Been thanked: 18 times

Return to Visual Basic

Who is online

Users browsing this forum: No registered users and 1 guest

cron