Afla dimensiunea unui fisier

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

Afla dimensiunea unui fisier

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

Code: Select all

Private Declare Function GetCompressedFileSize _
                Lib "kernel32" _
                Alias "GetCompressedFileSizeA" (ByVal lpFileName As String, _
                                                lpFileSizeHigh As Long) As Long

Public Function GetFileSize(FilePath As String, BytesKbMb As Boolean) As String

    'Variable Declaration
    Dim FSize As Double

    'Verify that the FilePath is given
    If Len(FilePath) <> 0 Then
        'Getting FileSize in bit
        FSize = GetCompressedFileSize(FilePath, ByVal 0&)

        If FSize < 1024 Then
            If BytesKbMb = True Then
                GetFileSize = FSize & " Bytes"
            Else
                GetFileSize = FSize
            End If
           
        ElseIf FSize >= 1024 And FSize < 1048576 Then

            If BytesKbMb = True Then
                GetFileSize = Round(FSize / 1024, 2) & " KB"
            Else
                GetFileSize = Round(FSize / 1024, 2)
            End If
           
        ElseIf FSize >= 1048576 Then

            If BytesKbMb = True Then
                GetFileSize = Round(FSize / 1048576, 2) & " MB"
            Else
                GetFileSize = Round(FSize / 1048576, 2)
            End If
           
        End If

    Else

        Exit Function

    End If

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: 21 Nov 2017 07:19
Has thanked: 10 times
Been thanked: 18 times

Return to Visual Basic

Who is online

Users browsing this forum: No registered users and 2 guests

cron