You Are Here:

Community: Wiki

This page was last modified on 24 October 2009, at 11:27.

Find Files

From Forum Nokia Wiki

Reviewer Approved   

Following code snippet illustrates how to find files from the given path.

Header and library

#include <f32file.h> //include header
efsrv.lib // add in mmp.

Modify your container as follows:

void CYrContainer::FindFile()
{
_LIT(KPath,"C:\\System\\"); // Give your path here
_LIT(KFileName,"*.txt"); // Give file name here
RFs fs;
fs.Connect();
CleanupClosePushL(fs);
CDesCArrayFlat* files = new (ELeave) CDesCArrayFlat(5);
CleanupStack::PushL(files);
 
StartScanL(fs, KPath, KFileName, files); // Result will be stored in files array
 
CleanupStack::PopAndDestroy(files);
CleanupStack::PopAndDestroy(&fs);
}
 
void CYrContainer::StartScanL(
RFs aFs, const TDesC& aPath, const TDesC& aWild, CDesCArray* aArray)
{
CDirScan* DirScan = CDirScan::NewLC(aFs);
DirScan->SetScanDataL(aPath,
KEntryAttDir|KEntryAttMatchExclusive,
ESortNone, CDirScan::EScanDownTree);
 
while(1)
{
CDir* dir = NULL;
TRAPD(error, DirScan->NextL(dir));
if (error || !dir)
break;
 
delete dir;
 
ScanDirectoryL(aFs, DirScan->FullPath(), aWild, aArray);
};
CleanupStack::PopAndDestroy(DirScan);
}
 
void CYrContainer::ScanDirectoryL(
RFs& aFs, const TDesC& aDir, const TDesC& aWild, CDesCArray* aArray)
{
TParse parse;
parse.Set(aWild, &aDir, NULL);
TPtrC spec(parse.FullName());
 
TFindFile FindFile(aFs);
CDir* dir;
 
if (!FindFile.FindWildByPath(parse.FullName(), NULL, dir))
{
CleanupStack::PushL(dir);
 
for(TInt i = 0; i < dir->Count(); i++)
{
parse.Set((*dir)[i].iName, &spec, NULL);
aArray->AppendL(parse.FullName());
}
CleanupStack::PopAndDestroy(dir);
}
}

Output: All files under C:\System\ having extension .txt will be stored in an array files(of type CDesCArrayFlat).

  • Replace KPath and KFileName as per your requirements.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia