OpenFile()
Syntax
Result = OpenFile(#File, Filename$)Description
It will open the designated file or create it if it doesn't exists. Read and write can be performed on this file. OpenFile() will be used the same way like 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 is effectively opened, else the file can't 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():If OpenFile(0, "Test.txt") ; opens an existing file or creates one, if it doesn't 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 can be a problem to manipulate a file on a CD-ROM. To read from a file, it is better to use the ReadFile() instead.
Supported OS
All