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);
阅读(1162) | 评论(0) | 转发(0) |