FileLength
PowerScript function
Description
Reports the length of a file whose size does not exceed 2GB in
bytes.
Syntax
1 |
FileLength ( filename ) |
Argument |
Description |
---|---|
filename |
A string whose value is the name of the file for which you |
Return value
Long.
Returns the length in bytes of the file identified by filename. If
the file does not exist, FileLength returns -1. If filename is null,
FileLength returns null.
Usage
Call FileLength before or after you call FileOpen to check the
length of a file before you call FileRead. The FileRead function can read
a maximum of 32,765 bytes at a time. The length returned by FileLength
always includes the byte-order mark (BOM). For example, suppose the
hexadecimal display of the file SomeFile.txt is FF FE 54 00 68 00 69 00 73
00, then the following statement returns 10,which includes the BOM:
1 |
ll_length = FileLength("SomeFile.txt") |
File security
If any security is set for the file (for example, if you are
sharing the file on a network), you must call FileLength before FileOpen
or after FileClose. Otherwise, you get a sharing violation.
The FileLength function cannot return the length of files whose size
exceeds 2GB. Use FileLength64 to
find the length of larger files.
Examples
This statement returns the length of the file EMPLOYEE.DAT in the
current directory:
1 |
FileLength("EMPLOYEE.DAT") |
These statements determine the length of the EMP.TXT file in the
EAST directory and open the file:
1 2 3 4 5 |
long LengthA integer li_FileNum LengthA = FileLength("C:EASTEMP.TXT") li_FileNum = FileOpen("C:EASTEMP.TXT", & TextMode!, Read!, LockReadWrite!) |
The examples for FileRead illustrate reading files of different
lengths.
See also