mFileSize

Okay with this little function you can retrieve the compressed file size of a file of your choice.

Option Explicit
‘—————————————————————————————
‘ Module : mFileSize
‘ DateTime : 25.12.09 02:19
‘ Author : Kreshnik Hasanaj
‘ Mail : kresha7@hotmail.com
‘ Usage : At your own risk.
‘ Purpose : Get the size of a file
‘ Distribution: You can freely use this code in your own
‘ applications, but you may not reproduce
‘ or publish this code on any web site,
‘ online service, or distribute as source
‘ on any media without express permission.
‘—————————————————————————————
Private Declare Function GetCompressedFileSize _
Lib “kernel32” _
Alias “GetCompressedFileSizeA” (ByVal lpFileName As String, _
lpFileSizeHigh As Long) As Long

Public Function GetFileSize(FilePath As String) 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
GetFileSize = FSize & ” Bytes”
ElseIf FSize >= 1024 And FSize < 1048576 Then
GetFileSize = Round(FSize / 1024, 2) & ” KB”
ElseIf FSize >= 1048576 Then
GetFileSize = Round(FSize / 1048576, 2) & ” MB”
End If

Else
Exit Function
End If

End Function

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s