OpenFile()
Syntax
Result = OpenFile(#File, Filename$)Description
It will open the designated file or create it if it does not exists. Read and write may be performed on this file. OpenFile() will be used in the same manner as the "read-only" ReadFile() and the "write-only" CreateFile() functions. When an existing file is opened using OpenFile(), the file pointer is positioned at the beginning of the file.
If #PB_Any is used as '#File' parameter, the new file number will be returned as 'Result'.
If 'Result' is not 0, the file has been effectively opened, else the file may not be opened. The result must be always tested, as performing operations on a non-opened file will cause a severe crash.
If the #File was already used, the previous file will be closed automatically.
If data should be added to an existing file, the file pointer must be set to the end of the file first. For this the commands FileSeek() and Lof() are used after OpenFile():Example:
If OpenFile(0, "Test.txt") ; opens an existing file or creates one, if it does not exist yet FileSeek(0, Lof(0)) ; jump to the end of the file (result of Lof() is used) WriteStringN(0, "... another line at the end.") CloseFile(0) EndIf
Note: when using OpenFile() the file must have the rights for reading AND writing. For example, this may be a problem when attempting to manipulate a file on a CD-ROM. To read from a file, the preferred method is to use the ReadFile() function instead.
Supported OS
All