444
Platforms
©2000-2008 Tibbo Technology Inc.
'will open two files 'on' numbers 3 and 5
fd.filenum=3
If
fd.open("File1")<>PL_FD_STATUS_OK
Then
'some problem
End
If
fd.filenum=5
If
fd.open("TrestFile")<>PL_FD_STATUS_OK
Then
'some problem
End
If
Whenever you want to work with one of the currently opened files, just set the fd.
filenum to the number on which this file was opened (naturally, you need to
somehow remember this number). And how many files can be opened
concurrently? The
R/O property will tell you that. This value
is platform-dependent. Your fd.filenum value can move between 0 and fd.
maxopenedfiles-1.
When the file is opened "on" a certain file number, the
R/O
property returns 1- YES when this file number is selected in the fd.filenum.
Several additional notes:
Any leading spaces in the file name you supply for fd.open are removed. After that,
only the part up to the first space is processed -- the rest of the string is ignored.
The following three code lines all open the same file:
fd.open("File1")
fd.open(" File1")
'leading spaces will be removed
fd.open("File1 some more stuff")
'everything after the first space will be
ignored too
Naturally, the file with the specified name must exist, or you get the 9-
PL_FD_STATUS_NOT_FOUND error. You may not open the same file "on" two
different file numbers -- this will generate the 11-
PL_FD_STATUS_ALREADY_OPENED error. You may reopen the same file "on" the
same file number, but this can lead to the loss of (some) changes made to the file
prior to re-opening. To avoid this,
method
before opening it again. Note that the fd.flush method does not depend on the
current fd.filenum value and works globally on any most recently changed file.
Writing To and Reading From Files
Writing to and reading from files are two most important file operations. Having a
flash disk would be pointless without them. Writing and reading is done using two
methods --
and
respectively. These work on a currently
selected file, and the selection is made through the
property.
Both reading and writing operations are always performed from the current pointer
position. This position can be checked through the
R/O property and
changed through the
method. Executing the fd.setdata or fd.
getdata moves the pointer forward by the number of file positions written or read.
The pointer always points at the position (offset) in the file from which the next
reading or writing will be done. File offsets are counted from one, not zero. The
very first byte in the file is at offset one, the next byte -- at offset two, and so on.
The very last byte in the file is at offset equal to the size of the file, which is
indicated by the
R/O property. The maximum pointer value, however,
473
464
448
466
480
469
463
476
482
464