FileLen

Returns a Long specifying the length of a file in bytes.

Syntax: FileLen( pathname )

pathname
required String expression that specifies a file name. The pathname may include the directory or folder, and the drive.

If the specified file is open when the FileLen function is called, the value returned represents the size of the file immediately before it was opened.

Note

Use the LOF function to obtain the length of an open file.

Common Errors

Error When
-2147467259 (&H80004005), Unspecified error no file or folder has the name pathname, which includes a zero-length string, a folder named with a backslash at its end, and a name with a character a name cannot hold
the folder or drive named in pathname does not exist
pathname holds a wildcard that matches no file or folder
94 (&H5E), Invalid use of Null pathname is Null

Note BETA 1034

When no file or folder has the name pathname, which includes a zero-length string, a folder named with a backslash at its end, and a name with a character a name cannot hold, VB6 and 64-bit VBA raise error 53 (&H35), File not found, instead.

Note BETA 1034

When the folder or drive named in pathname does not exist, VB6 and 64-bit VBA raise error 76 (&H4C), Path not found, instead.

Note BETA 1034

When pathname holds a wildcard that matches no file or folder, VB6 and 64-bit VBA raise error 52 (&H34), Bad file name or number, instead.

Note BETA 1034

When pathname holds a wildcard that matches a file or folder, VB6 and 64-bit VBA raise error 52 (&H34), Bad file name or number; twinBASIC raises none.

Example

This example uses the FileLen function to return the length of a file in bytes. For purposes of this example, assume that TESTFILE is a file containing some data.

Dim MySize
MySize = FileLen("TESTFILE")    ' Returns file length (bytes).

See Also