Get File Length 2 Method
The Get File Length 2 method returns the length of a file. If the file is open, then it returns the length of the file before it was opened. The file can be closed or open to use this method.
Format
FileLen(pathname)
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
pathname |
A string or string expression that evaluates to the name of the file to query. It cannot include the following wildcards:
|
Example
The following example returns the length of a file:
Sub Button_Click
Dim length as Long
Dim userfile as String
Dim msgtext
On Error Resume Next
msgtext = "Enter a file name:"
userfile = "trace.txt"
length = FileLen(userfile)
If Err <> 0 then
msgtext = "Error occurred. Rerun program."
Else
msgtext = "The length of " & userfile & " is: " & length
End If
End Sub