Walking Through the File Directory
Discussed in this topic: fd.resetdirpointer, fd.getnextdirmember, fd.getnumfiles.
At times, it is necessary to get the list of all files stored on the flash disk. Most operating systems provide this feature in the form of a DIR command. The fd. object offers two methods — fd.resetdirpointer and fd.getnextdirmember — that allow you to get the names of all stored files one by one.
An imaginary "directory pointer" walks through the file record table (FRT) of the flash disk. The fd.resetdirpointer method resets the directory pointer to 0 (i.e., to the very first directory record). The fd.getnextdirmember method returns the next file name and advances the pointer. Only file names are returned; attributes are excluded.
Calling the fd.getnextdirmember method repeatedly will get you all the file names. When there are no more names left to go through, the method will return an empty string. You can use this to end your directory walk:
'walk through the file directory -- method #1
Dim s As String
fd.resetdirpointer
Do
s=fd.getnextdirmember
If fd.laststatus<>PL_FD_STATUS_OK Then
'some problem
End If
... 'process the file name in s
Loop While s<>"" 'we exit on empty string
Alternatively, you can use a for-next cycle, since the number of currently stored files can be checked through the fd.getnumfiles method:
'walk through the file directory -- method #2
Dim s As String
Dim f As Byte
fd.resetdirpointer
For f=1 To fd.getnumfiles
s=fd.getnextdirmember
If fd.laststatus<>PL_FD_STATUS_OK Then
'some problem
End If
... 'process the file name in s
Next f