Monday, October 11, 2010

Visual Basic File System Function : FileLen

Purpose : the FileLen function returns the total length of a file in bytes.

Syntax :
FileLen ( filename$ )

totalBytes = FileLen ( Dir ( ) )

It return a long integer indicating the total number of bytes in the file.

1 comment:

  1. Only if the file size does not exceed 2 gigabytes. Otherwise, it can (and will) return a negative number. In VB6, the only way I know to get the true file size, especially for files of > 4 gigabytes is:

    Public Function DblGetFileSize(fname As String) As Double
    On Error Resume Next
    Dim fs, f, s

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(fname)
    DblGetFileSize = f.size
    Set f = Nothing
    Set fs = Nothing
    End Function

    It will return a double type that will be the true size of the file.

    ReplyDelete