Filtering Directory Content

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Created: vinayhosmani (22 Jun 2007)
Last edited: hamishwillee (23 Jul 2012)

This code is to filter the files of desired extension from a folder. Here the desired path is retrieved by use of PathInfo class.

Header Reqired:

#include <f32file.h> 
#include <pathinfo.h> //for PathInfo

Library Needed:

LIBRARY efsrv.lib 
LIBRARY platformenv.lib //for PathInfo


In class declaration add these lines

RArray<TEntry> iFileList;


void CMyclass::ListDirectory( )
CDir* dirs = 0;
CDir* files = 0;
TFileName path;
User::LeaveIfError(iFsSession.GetDir(path,KEntryAttNormal,ESortByName,files, dirs));
TFindFile findFiles( iFsSession );
TInt err = findFiles.FindWildByDir( KFileExtension, path, files );
CleanupStack::PushL( dirs );
CleanupStack::PushL( files );
//get files in base path
while (err == KErrNone)
for( TInt i=0; i<files->Count(); i++ )
iFileList.Append( (*files)[i] );
err = findFiles.FindWild( files );
CleanupStack::PopAndDestroy( 2 );

Now iFileList contains the files of desired extension. Here the list will contain only the mp3 files from c:\Nokia\Sounds\Digital directory. PathInfo class can determine various system paths for games, videos, images etc.



See also: Directory Monitoring

This page was last modified on 23 July 2012, at 11:02.
36 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.