Your main problem is re-using one and the same variables ("fref" and "it") for
different enumerations. Use different variables for the iterator and the
reference for the three levels - volume, directory and file - and that problem
will go away.
Also, your directory traversal algorithm looks wrong to me - but that depends
on where you expect to find the file you're looking for. Can it be *anywhere*
on the card? Then you need a full directory tree traversal - recursive or not.
As it is now, your algorithm expects that the file is either in the root
directory or immediately in the first subdirectory. If this is an unreallistic
expectation, you have to change your algorithm, so that as soon as it sees a
directory, it enters that directory - no matter how deep. And, as soon as it
can no longer find any files in the current directory, it backtracks to where
it was, continuing with the files remaining in the directory at the higher
level - and any other subdirectories there, too.
Also, keep in mind that the card can be big (2 Gb?) and can contain thousands
of files and directories. Bad things might happen if you try to put all of them
in a list, as the above code tries to do. (I don't understand why your current
code assumes that there can be no more than 80 of them.) Even just traversing
them could be rather time-consumming - dozens of seconds, even on a reasonably
fast device. It would be best (but the most difficult to implement) if you
could do what you want one file at a time (i.e., without the need to present
all of them in a list to the user) and if you do it in a non-recursive way. I
did that recently for the application I'm writing.
There are a few gotchas if you choose this approach, though. Non-recursive tree
traversal is a bitch - you'll have to maintain your own stack. You'll have to
preserve the values of the references (volume, directory and file) and of the
iterators between calls to the event handler of the form that does the scanning
- for that you need either global or static variables (not available if your
program is not launched normally) or you have to do stupid tricks like
allocating the memory to hold them and saving a pointer to that memory in a
feature.
Regards,
Vesselin
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/