Wednesday, April 29, 2009

Get File Size

'Get File Size
' This project needs

'1 Command Button (Command1)

'1 CommonDialog (CommonDialog1)

'1 Label (Label1)

'Add Component (CTRL+T )

'Controls > Ms Common Dialog Control (COMDLG32.OCX)



Private Const OF_READ = &H0&

Private Declare Function lOpen
Lib "kernel32"
Alias "_lopen" _

(ByVal
lpPathName As String, ByVal iReadWrite
As Long) As Long

Private Declare Function lclose
Lib "kernel32"
Alias "_lclose" _

(ByVal hFile As Long)
As Long
Private Declare Function
GetFileSize Lib "kernel32" (ByVal hFile
_

As Long, lpFileSizeHigh As Long)
As Long
Dim lpFSHigh
As Long


Public Sub GetInfoFile(FilePath
As String)

Dim Pointer As Long,
SizeFile As Long
Pointer = lOpen(FilePath, OF_READ)

 'GET size of the file
SizeFile = GetFileSize(Pointer, lpFSHigh)
Label1.Caption
= SizeFile & " bytes"

lclose Pointer
End Sub


Private Sub command1_Click()

CommonDialog1.ShowOpen GetInfoFile
CommonDialog1.filename

End Sub


Private Sub Form_Load()
CommonDialog1.DialogTitle = "Select a file"
CommonDialog1.Filter = "All the
files|*.*"
Command1.Caption = "Select a file"

End Sub



No comments:

Post a Comment