遍历Symbian某目录下的所有文件

本文介绍了两种在Symbian系统中遍历指定目录下所有文件的方法,包括使用RFs::GetDir()方法和RDir类。这两种方法可以帮助开发者实现类似程序管理器的功能。

遍历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指针即可。

那么我们再看看CDir这个类的SDK HELP

Class CDir

CDir

Support

Supported from 5.0

Description

Array of directory entries that has been read into memory from the file system — abstract base class. It can be read and sorted by user programs, but cannot be created by them.

This class is not intended for user derivation.

注释:一个数组,这个数组的内容是从文件系统扫描到的目录,目录被缓存到内存中。它可以被我们的程序读取和排序,但是不能创建。

Derivation

o    CBase - Base class for all classes to be instantiated on the heap

§         CDir - Array of directory entries that has been read into memory from the file system — abstract base class

Members

Defined in CDir:
Count(), NewL(), Sort(), operator[](), ~CDir()

Inherited from CBase:
operator new()

    可见,这个类派生自CBase,并且继承了CBasenew()运算符。它里面只有5个方法,去处析构函数,实际上只有4个有用的方法。并且它里面重新定义了[]操作符,因为CDir本身是一个目录的数组。它还可以排序、可以计算数量,这些都是数组的基本特性。NewL()只不过也是一个重载的运算符而已。

    再看看operator[]()的定义:

operator[]()

const TEntry& operator[](TInt anIndex) const;

Description

Returns an entry from the array.

Parameters

TInt anIndex

Index of the desired entry within the array.

Return value

TEntry&

A directory entry.

    可以看出,通过[]操作符,CDir指针返回给我们的是一个目录的封装类TEntry

 

我们可以再跟踪一下TEntry这个类的SDK HELP

Class TEntry

TEntry

Support

Supported from 5.0

Description

Encapsulates an entry in a directory, which can be another (nested) directory, a file or a volume label. Each directory entry has a name which is relative to its owning directory and a type, which is indicated by its unique identifier (UID).

注释:封装目录中的一项内容,内容可以是另一个(嵌套的)目录、一个文件或者是一个驱动器卷标。每个目录项都有一个名字和类型与它的所属目录相关联,也就是UID所显示出来的东西。

An entry can be interrogated for the following properties:

一项内容可以被提取以下的属性:

·         the kind of entry: stored in the entry UIDs, stored in iType(项的类型:储存在UIDsiType)

·         the entry attributes, stored in iAtt(项的属性:储存在iAtt)

·         the size of entry(项的尺寸)

·         the time the entry was last modified(项上次被修改的时间)

Members

Defined in TEntry:
IsArchive(), IsDir(), IsHidden(), IsReadOnly(), IsSystem(), IsTypeValid(), IsUidPresent(), MostDerivedUid(), iAtt, iModified, iName, iSize, iType, operator[]()

See also:

    通过以上SDK HELP的内容,我们就知道了大概的方向,从而尝试写出了以下的程序:

void CCountEntryAppUi::ConstructL()

    {

    BaseConstructL();

 

    RFs iFs;

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

    _LIT(KDIR,"C://");

    CDir* dir; 

    User::LeaveIfError(iFs.GetDir(KDIR,KEntryAttNormal|KEntryAttMatchMask,ESortByDate,dir));

    TInt tempInt = dir->Count();

    for(int i = 0;i < tempInt;i++)

    {

        TEntry& iEntry = (TEntry&)dir[i];

        TBufC<256> iFileName = iEntry.iName;

    }

 

    delete dir;

    dir = NULL;

 

    iAppContainer = new (ELeave) CCountEntryContainer;

    iAppContainer->SetMopParent( this );

    iAppContainer->ConstructL( ClientRect() );

    AddToStackL( iAppContainer );

}

通过设置断点进行观察,可以看到如下结果:

Symbian系统C盘下的文件内容如下:

可见,此时程序所读取到的文件数目是正确的。

 

  下面我们来看第二中获取Symbian某目录下所有文件的方法,其基本原理是类似的,只不过是调用了不同的接口而已。

    RFs iFs;

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

    _LIT(KDIR,"C://");

 

    RDir oDir;

    oDir.Open(iFs, KDIR, KEntryAttNormal);

    TEntryArray* oArray = new (ELeave) TEntryArray;

    oDir.Read(*oArray);

    TInt iCount = oArray->Count();

 

    for(TInt i = 0;i < iCount;i++)

 

    {

        TEntry temp = (*oArray)[i];

        TName iTemp = temp.iName;

 

        if(i == 2)

            CEikonEnv::Static()->InfoMsg(iTemp);

    }  

iFs.Close();

和第一种方法不同的是,这里使用了RDir类作为目录项的存放数组。我们看看SDK HELP中这个类的帮助文档:

RDir

Support

Supported from 5.0

Description

Reads the entries contained in a directory.

读取一个目录中所包含的项,包括目录、文件以及驱动器卷标,这一点和上面的CDir类是一样的。

You must first open the directory, specifying an attribute mask which is used by Read() calls to filter the entry types required. Then, use one of the Read() functions to read the filtered entries. When the operation is complete, the directory should be closed using Close(), defined in the base class RFsBase.

你必须先打开目录,定义一个属性掩码用来过滤项类型。然后用Read()函数去读取过滤的项。当操作完成时,目录应该调用基类RFsBase中定义的Close()方法关闭。

There are two types of Read(): one works with a single entry at a time, requiring programs to iterate through the entries explicitly. The other works with an entire TEntryArray, allowing multiple entries to be read in one call. As well as making application program logic somewhat simpler, this type uses fewer calls to the server, and is more efficient.

有两种版本的Read()方法:一种是每次读取一个目录项,要求遍历所有目录项。另一种利用一个TEntryArray工作,它允许多个目录项一次读取完。为了让应用程序逻辑简单,这种类型和服务器的交互少,并且非常高效。

Each type of Read() can be performed either synchronously or asynchronously.

每种版本的Read()方法都可以表现为同步的或者异步的。

It may be more convenient to use RFs::GetDir() than the Read() calls supported by this class. RFs::GetDir() has the advantage that it allows a directory's entries to be sorted in various ways. However, it does not provide asynchronous as well as synchronous variants and does not allow entries to be read individually.

RFs::GetDir()比这个类所提供的方法更方便,而且RFs::GetDir()允许一个目录的项以不同的方式排序。尽管如此,RFs::GetDir()却不区分同步、异步的方式,并且不允许目录项逐个的读取。

Derivation

    • RSubSessionBase - Client-side handle to a sub-session
      • RFsBase - Base class that provides a Close() function for file related clean-up
        • RDir - Reads the entries contained in a directory

Members

Defined in RDir:
Open(), Open(), Read(), Read(), Read(), Read()

Inherited from RFsBase:
Close()

Inherited from RSubSessionBase:
CloseSubSession(), CreateSubSession(), Send(), SendReceive(), SubSessionHandle(), operator=()

 

看到这里,再和第一种方法进行比较,就应该很容易明白开头所给出的代码了,这段代码在VS2003+Carbide.vs+ S60_2nd_FP2_SC SDK中也编译通过.




内容概要:本文介绍了一套针对智能穿戴设备的跑步/骑行轨迹记录系统实战方案,旨在解决传统运动APP存在的定位漂移、数据断层和路径分析单一等问题。系统基于北斗+GPS双模定位、惯性测量单元(IMU)和海拔传感器,实现高精度轨迹采集,并通过卡尔曼滤波算法修正定位误差,在信号弱环境下利用惯性导航补位,确保轨迹连续性。系统支持跑步与骑行两种场景的差异化功能,包括实时轨迹记录、多维度路径分析(如配速、坡度、能耗)、数据可视化(地图标注、曲线图、3D回放)、异常提醒及智能优化建议,并可通过蓝牙/Wi-Fi同步数据至手机APP,支持社交分享与专业软件导出。技术架构涵盖硬件层、设备端与手机端软件层以及云端数据存储,强调低功耗设计与用户体验优化。经过实测验证,系统在定位精度、续航能力和场景识别准确率方面均达到预期指标,具备良好的实用性和扩展性。; 适合人群:具备一定嵌入式开发或移动应用开发经验,熟悉物联网、传感器融合与数据可视化的技术人员,尤其是从事智能穿戴设备、运动健康类产品研发的工程师和产品经理;也适合高校相关专业学生作为项目实践参考。; 使用场景及目标:① 开发高精度运动轨迹记录功能,解决GPS漂移与断点问题;② 实现跑步与骑行场景下的差异化数据分析与个性化反馈;③ 构建完整的“终端采集-手机展示-云端存储”系统闭环,支持社交互动与商业拓展;④ 掌握低功耗优化、多源数据融合、动态功耗调节等关键技术在穿戴设备中的落地应用。; 阅读建议:此资源以真实项目为导向,不仅提供详细的技术实现路径,还包含硬件选型、测试验证与商业扩展思路,建议读者结合自身开发环境,逐步实现各模块功能,重点关注定位优化算法、功耗控制策略与跨平台数据同步机制的设计与调优。
内容概要:《QTools_V4.6.1用户手册》详细介绍了一款专为AutoCAD及CASS设计的辅助插件,涵盖测绘、设计等多个领域,提供超过400项实用功能。主要包括拓扑检查(如碎线、碎面、短边、弧段、锐角等检查)、图形与文字处理工具(如批量插图、文字对齐、编号、合并、替换等)、测绘专用工具(如断面、高程点、等高线、三角网处理)、以及图纸管理功能(如拆分、合并、解密、批量修改)等。插件支持云授权和加密锁两种激活方式,兼容AutoCAD 2004–2026及各版本CASS,并提供侧边栏、菜单栏、自定义命令等多种操作方式,同时具备自动更新与性能检测功能。; 适合人群:从事测绘、地理信息、建筑设计等相关领域的技术人员,熟悉AutoCAD/CASS操作,具备一定工程制图经验的从业人员。; 使用场景及目标:①用于地形图、地籍图、宗地图等专业图纸的自动化处理与质量检查;②提升CAD绘图效率,实现批量操作、数据提取、格式转换、拓扑修复等任务;③支持测绘项目中的断面绘制、高程分析、坐标展点、土方计算等核心流程;④解决图纸编辑受限、字体缺失、块无法分解等问题。; 阅读建议:建议结合实际项目操作手册中的功能命令,优先掌握常用快捷指令(如qq、tp、dm、gcd等),并利用“功能搜索”快速定位工具。使用前确保正确加载插件并完成授权,遇到问题可参考“常见问题”章节进行排查。定期关注更新内容以获取新功能和优化体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值