Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1021128
  • 博文数量: 326
  • 博客积分: 10135
  • 博客等级: 上将
  • 技术积分: 2490
  • 用 户 组: 普通用户
  • 注册时间: 2006-04-22 23:53
文章分类

全部博文(326)

文章存档

2014年(1)

2012年(4)

2011年(1)

2010年(4)

2009年(41)

2008年(44)

2007年(63)

2006年(168)

我的朋友

分类:

2007-03-05 14:55:40

In order to list the files from a directory, you need to use the RFs class (RFs is a class that allows you to access the file server).

The method TInt RFs::GetDir(const TDesC& aFileSpec, TUint anEntryAttMask, TUint anEntrySortKey, CDir*& anEntryList) returns a CDir pointer, which list all file entries in directory aFileSpec (the return value should be KErrNone).

The following example creates a listing and opens all files:


RFs fileSession;
RFile file;
CDir* dirList;
TInt i;
TBuf<50> totalPath;
TBuf<30> fileName;
_LIT(KDirName, "C:\\FolderXY\\");
_LIT(KFileSpec,"C:\\FolderXY\\*.*");

//
// Connect to the file server
//
fileSession.Connect();
CleanupClosePushL(fileSession);

//
// Get the file list, sorted by name
// (Leave if an error occurs)
//
User::LeaveIfError(
     fileSession.GetDir(KFileSpec,
                        KEntryAttMaskSupported,
                        ESortByName,
                        dirList));
CleanupStack::PushL(dirList);

//
// Process each entry
//
for (i=0;iCount();i++)
{
 fileName = (*dirList)[i].iName;
 totalPath = KDirName;
 totalPath.Append(fileName);
 DoAnythingYouWantWithTheFile(totalPath);
}

//
// Close the connection with the file server
// and destroy dirList
//
CleanupStack::PopAndDestroy(2);

阅读(1130) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~