×
Namespaces

Variants
Actions

Reading Content of Directory Effectively

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
Created: kamaljaiswal (25 Oct 2007)
Last edited: hamishwillee (26 Jul 2012)

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);
}
}
This page was last modified on 26 July 2012, at 08:08.
17 page views in the last 30 days.