FileLen Function

Named Arguments

No

Syntax

FileLen(pathname)

Pathname

Use: Required

Data Type: String

The filename, optionally along with its path and drive.

Return Value

A Long data type containing the length of the specified file in bytes.

Description

Indicates the length of a file.

Rules at a Glance

If you don't specify a drive or folder with filename, the file is assumed to be in the current drive or folder.

Programming Tips and Gotchas

  • Use the Dir function to determine that the file exists before calling File-DateTime. If the file doesn't exist, FileDateTime generates runtime error 53, "File not found." Another method of determining that a file exists before referencing it comes from the new FileSystemObject object in VB6, which includes a FileExists method.

  • Because FileLen returns the length of a file based on the file allocation table, the value returned by FileLen reflects the size of the file before it was opened. In the case of open files, you should instead use the LOF function to determine the open file's current length.

See Also

FileDateTime Function, LOF Function, File System Objects

Get VB & VBA in a Nutshell: The Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.