Reading Content of Directory Effectively
Article Metadata
The RDir class allows you to open a directory and read the entries it contains. There are several different ways to read the contents of a directory.
Each call to Read() reads a single entry, which is useful in cases where memory usage needs to be minimized.
However, it is inefficient to make multiple calls to a server function, so RDir also supplies an overloaded method Read() that, in a single call, reads several entries into a TEntryArray.
The number of entries contained in each TEntryArray cannot be determined before a call to Read() because the length of each file or directory name is likely to be different.
void ReadDirContentsL(RFs& aFs, const TDesC& aDirName)
{
RDir myDir;
TInt err;
User::LeaveIfError(myDir.Open(aFs, aDirName,
KEntryAttNormal| KEntryAttDir));
TEntry currentEntry;
FOREVER
{
err = myDir.Read(currentEntry);
if (err)
{
break; // No more entries, or some other error
}
// Process this entry
}
myDir.Close()
if (err != KErrEof) // EOF signifies no more entries to read
{
User::LeaveIfError(err);
}
}


(no comments yet)