WEB开发网
开发学院手机开发Symbian 开发 symbian 获取指定路径下的文件夹列表 阅读

symbian 获取指定路径下的文件夹列表

 2010-06-22 02:51:00 来源:WEB开发网   
核心提示:// 定义路径#ifdef _DEBUG_LIT(KPath, "c:\System\Apps\myfile");//C盘对应epoc32winsc#else_LIT(KPath, "e:\myfile");// e盘对应手机上的e盘#endif// 用于保存文件夹名称RPoin

// 定义路径

#ifdef _DEBUG

_LIT(KPath, "c:\System\Apps\myfile");//C盘对应epoc32winsc

#else

_LIT(KPath, "e:\myfile");// e盘对应手机上的e盘

#endif

// 用于保存文件夹名称

RPointerArray iFolderlist;

// 第一种方法

CDirScan* ds = CDirScan::NewLC(CCoeEnv::Static()->FsSession());

TRAPD(err,ds->SetScanDataL(KPath,KEntryAttNormal,ESortByName|EAscending,CDirScan::EScanDownTree));

if (err!=KErrNone)

{

CleanupStack::PopAndDestroy(ds);

return;

}

TPtrC str(gAppPath);

int nPathLen = str.Length();

TFileName fullname;

CDir* c = NULL;

while(1)

{

ds->NextL(c);

if (!c)

{

break;

}

fullname.Copy(ds->FullPath());

int nNameLen = fullname.Length() - nPathLen;

if(nNameLen > 0)

{

HBufC* foldername = HBufC::NewL(20);

*foldername = fullname.Mid(nPathLen, nNameLen-1);

iFolderlist.AppendL(foldername);

}

delete c;

c=NULL;

}

CleanupStack::PopAndDestroy(ds);

iFolderlist.ResetAndDestroy();

// 第二种方法

RFs Fs;

User::LeaveIfError(Fs.Connect());

CDir *dir = NULL;

// 获取KPath下的文件和文件夹列表

User::LeaveIfError(Fs.GetDir(KPath,KEntryAttNormal|KEntryAttMatchMask,ESortNone,dir));

for (TInt i=0; i

Count(); i++)

{

// 如果是文件夹,就将文件夹名称保存到iFolderlist

if ((*dir)[i].IsDir())

{

HBufC* foldername = (*dir)[i].iName.AllocL();

iFolderlist.AppendL(foldername);

}

}

delete dir;

dir = NULL;

Fs.Close();

iFolderlist.ResetAndDestroy();

注:

第一种方法在执行ds->NextL(c);时非常耗时,本人用N6670手机试过,当KPath下有340个左右的文件和文件夹时,耗时大概是15秒,而用第二种方法不到1秒,所以建议使用第二种方法.

End.............

  原文:http://blog.csdn.net/miyunhong/archive/2010/06/20/5681381.aspx

Tags:symbian 获取 指定

编辑录入:coldstar [复制链接] [打 印]
赞助商链接