|
-
Mar 9th, 2002, 08:41 PM
#1
Thread Starter
Hyperactive Member
File Information
Without using the File System Object, how can I get the size of a file?
-
Mar 9th, 2002, 08:44 PM
#2
Private Const OPEN_EXISTING = 3
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type BY_HANDLE_FILE_INFORMATION
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
dwVolumeSerialNumber As Long
nFileSizeHigh As Long
nFileSizeLow As Long
nNumberOfLinks As Long
nFileIndexHigh As Long
nFileIndexLow As Long
End Type
Private Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Private Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As Any, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Command1_Click()
Dim hFile As Long
Dim FileInfo As BY_HANDLE_FILE_INFORMATION
'create a handle to the file 'c:\autoexec.bat'
hFile = CreateFile("c:\program files\MyFile.txt", 0, 0, ByVal 0&, OPEN_EXISTING, 0, ByVal 0&)
GetFileInformationByHandle hFile, FileInfo
'close the handle
CloseHandle hFile
MsgBox "File size: " + CStr(FileInfo.nFileSizeLow), vbInformation
End Sub[/Highlight]
-
Mar 9th, 2002, 08:45 PM
#3
Argggggg....I hate it when I mess up the code tags. Sorry about the AttnSue.
-
Mar 10th, 2002, 01:44 PM
#4
Or you could use the FileLen() function 
VB Code:
Private Sub Command1_Click()
Caption = FileLen("C:\SomeFile.txt")
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|