----- Original Message -----
From: "Dr. Vesselin Bontchev" <[EMAIL PROTECTED]>
> > Implement GetNextFile() like this:
> > Keep the directory list along with the enumeration.
> > At the beginning the dirList is initialized to the root dir.
> > 1. Pop a directory from the dirList or terminate (empty dirList).
> > 2. Start directory enumeration.
> > 3. If the enumeration yields a file, return it.
> > If a directory is obtained, add it to the dirList.
> > If the enumeration ends, go to step 1.
>
> Something is definitely wrong with this algorithm... OK, let's say that at
the beginning (before the first call to GetNextFile) I'll push "/" on the
stack. But in GetNextFile I can't pop an item off the stack as the first
thing it does every time it is called to obtain the next file - because then
all it will do is return the first file in the directory.
I did not write all details. There must be some
EnumStruct {
dirList ;
actDirHandle ;
actDirIterator ;
}
Handle CreateEnumerator()
{
create EnumStruct
str->dirList.add( "/") ;
str->actDirHandle = 0 ;
str->actDirIterator = EOF ;
return (Handle)str ;
}
GetNextFile( Handle h )
{
//....
if( actDirIterator == EOF )
{
if( actDirHandle != 0 )
close actDirHandle ;
LabelNextDir:
if( dirList.IsEmpty() )
return 0 ;
actDirHandle = dirList.pop() ;
actDirIterator = StartIterator ;
}
switch( VFSDirEntryEnumerate( actDirHandle, &actDirIterator ... ) )
{
case 0 :
test file/dir etc.
case expErrEnumerationEmpty:
goto LabelNextDir ;
default:
error processing ;
}
}
Etc. It is incomplete again, but it is just a question of filling the
implementation details. We use similar procedures often.
Best regards,
Jan Slodicka
--
For information on using the Palm Developer Forums, or to unsubscribe, please
see http://www.palmos.com/dev/support/forums/