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.
Declare a CDir
pointer.
This type holds an array of directory entries.
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.
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.
Delete the CDir
object
after use.
_LIT(KDir,"\\FileserverExample\\*"); CDir* dirList; User::LeaveIfError(fsSession.GetDir(KDir, KEntryAttMaskSupported,ESortByName,dirList)); _LIT(KString,"%S"); for (TInt i=0;i<dirList->Count();i++) console->Printf(KString,&(*dirList)[i].iName); delete dirList;
Notes
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.
Use GetDir()
to
provide a list of directories and files and additionally a separate list of
directories only.
If the attribute mask KEntryAttNormal
is
used, no system or hidden files or directories are included in the file list.
CDir* fileList; User::LeaveIfError(fsSession.GetDir(KDir, KEntryAttNormal,ESortByName,fileList,dirList));