Results 1 to 4 of 4

Thread: File Information

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2002
    Location
    Connecticut, USA
    Posts
    308

    File Information

    Without using the File System Object, how can I get the size of a file?

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    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]

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Argggggg....I hate it when I mess up the code tags. Sorry about the AttnSue.

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Or you could use the FileLen() function
    VB Code:
    1. Private Sub Command1_Click()
    2.     Caption = FileLen("C:\SomeFile.txt")
    3. 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
  •  



Click Here to Expand Forum to Full Width