FileLength PowerScript function
Description
Reports the length of a file whose size does not exceed 2GB
in bytes.
Syntax
|
1 |
<span>FileLength</span> ( <span>filename</span> ) |
|
Argument |
Description |
|---|---|
|
filename |
A string whose value is the name of the |
Return Values
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, then the following statement
FE 54 00 68 00 69 00 73 00
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 |
<span>FileLength</span>("EMPLOYEE.DAT") |
These statements determine the length of the EMP.TXT file
in the EAST directory and open the file:
|
1 |
long LengthA |
|
1 |
integer li_FileNum |
|
1 |
LengthA = <span>FileLength</span>("C:EASTEMP.TXT") |
|
1 |
li_FileNum = FileOpen("C:EASTEMP.TXT", & |
|
1 |
TextMode!, Read!, LockReadWrite!) |
The examples for FileRead illustrate reading
files of different lengths.