得到程序路径

来源:互联网 发布:linux 文件大小的单位 编辑:程序博客网 时间:2024/05/29 04:19
 得到程序路径

程序一般安装在手机内或存储卡内,下列代码允许程序动态生成其安装路径,当程序访问同目录下文件时可以使用。
这是通过CompleteWithAppPath(TDes& aFileName)完成的,所有的结果(包括盘符、路径和文件名,以及扩展名)都可在给定的描述符中返回。

Code:

#include <aknutils.h>    // for CompleteWithAppPath()
// aFileName parameter contains the name of the file to open,
// without any path information
void CSomeAppClass::OpenFileL(const TFileName& aFileName)
    {      
    TFileName fullPath(aFileName);
    // insert the full application path into the file name
    CompleteWithAppPath(fullPath); // from aknutils.h
    ... // (proceed to open the file)
    }


如,该应用程序安装在手机内存中,则下列代码:
_LIT(KDataFileName, “data.dat”);
OpenFileL(KDataFileName);
从C盘打开的文件可为:c:/system/apps/myapp/data.dat
原创粉丝点击