×
Namespaces

Variants
Actions
Revision as of 11:02, 23 July 2012 by hamishwillee (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Filtering Directory Content

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Article
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

CMyClass.h

In class declaration add these lines

RArray<TEntry> iFileList;

CMyclass.cpp

_LIT(KFileExtension,"*.mp3");
 
 
 
void CMyclass::ListDirectory( )
{
CDir* dirs = 0;
CDir* files = 0;
 
TFileName path;
path.Copy(PathInfo::PhoneMemoryRootPath());
path.Append(PathInfo::DigitalSoundsPath());
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.


 

Links

See also: Directory Monitoring

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