遍历Symbian某目录下的所有文件应该是Symbian中常用到的功能模块,比如你想写一个类似“程序管理器”的程序,那么首先的任务就是要先知道某目录下到底有那些文件,然后再筛选出你所需要的文件。
遍历Symbian某目录下的所有文件有两种方法
① 我们首先学习点预备知识
查看SDK HELP中的GetDir()方法,你会看到如下的内容:
GetDir()
TInt GetDir(const TDesC& aName,TUint anEntryAttMask,TUint anEntrySortKey, CDir*& anEntryList) const;
Description
Gets a filtered list of a directory's contents. The bitmask determines which file and directory entry types should be listed. The sort key determines the order in which they are listed.
注释:
得到一个目录下内容的过滤列表。
anEntryAttMask决定哪个文件和目录应该被列出。
anEntrySortKey决定这些内容按照什么顺序列出。
Notes:
If sorting by UID (ESortByUid is OR'ed with the entry sort key), then UID information will be included in the listing whether or not KEntryAttAllowUid is specified in anEntryAttMask.(如果按照UID排序,即anEntrySortKey参数的值定义为ESortByUid。那么UID信息将被包含在列表中不管anEntryAttMask参数是否定义了KEntryAttAllowUid)
The function sets anEntryList to NULL, then allocates memory for it before appending entries to the list. Therefore, anEntryList should have no memory allocated to it before this function is called, otherwise this memory will become orphaned.(这个函数把anEntryList参数设置为NULL,然后在添加文件项到列表之前为anEntryList分配内存空间。因此,该函数调用之前anEntryList应该没有分配内存,否则这部分内存会变成垃圾而被遗弃)
The caller of this function is responsible for deleting anEntryList after the function has returned.(此函数的调用者有责任删除anEntryList在函数返回)
Parameters
const TDesC& aName
Name of the directory for which a listing is required. Wildcards may be used to specify particular files.
TUint anEntryAttMask
Bitmask indicating the attributes of interest. Only files and directories whose attributes match those specified here can be included in the listing. For more information see KEntryAttMatchMask and the other directory entry details. Also see KEntryAttNormal and the other file or directory attributes.
TUint anEntrySortKey
Flag indicating the order in which the entries are to be sorted. This flag is defined in TEntryKey.
CDir*& anEntryList
On return contains a list of directory and file entries.
Return value
TInt
KErrNone if successful, otherwise another of the system-wide error codes.
这是RFs类中的一个方法,从上面的SDK HELP内容我们可以看出:如果我们想获取某个目录下的所有内容,那么只需获取相应目录的CDir指针即可。