How to list directories and files

This topic describe show to list directories and files together and separately.

The list of a directory's contents can obtained by using two variants of the function RFs::GetDir(). Both variants provide a filtered list of files and directories; the second additionally provides a separate list containing directories only. Both variants use an attribute mask to filter the entry types.

The following sections assume that some directories and a file have been created in a directory FileserverExample, and then lists them in alphabetical order.

Listing directories and files together

  1. Declare a CDir pointer. This type holds an array of directory entries.

  2. Use GetDir() to get a single list, in the CDir object, which can contain both file and directory entries.

    Use KEntryAttMaskSupported to indicate all five file attributes, and the directory attribute.

    Use ESortByName to order the entries alphabetically.

  3. CDir::operator[]() can be used to get the attributes, name, size and modification date and time of the TEntry at the specified index within the array.

  4. Delete the CDir object after use.

CDir* dirList;
for (TInt i=0;i<dirList->Count();i++)
delete dirList;


  • GetDir() supports the use of the two wildcard characters: * (meaning any sequence of characters within any part of a component), and ? (meaning any single character).

Listing directories and files separately

If you want files and directories to be listed separately, another variant of GetDir() should be used. On return, the first list contains only files, the second directories.

  1. Use GetDir() to provide a list of directories and files and additionally a separate list of directories only.

  2. If the attribute mask KEntryAttNormal is used, no system or hidden files or directories are included in the file list.

CDir* fileList;