您的位置:首页 > 编程语言 > PHP开发

得到文件路径信息 TParse

2010-01-18 23:44 162 查看
得到文件路径信息 TParse

上面根据 DriveList 及 Drive 方法可以得到驱动信息信息

DriveList 需要 CDir 对像保存列表,CDir 中的每一个数据都是 TEntry 类型的,所以根据 TEntry 可以得到驱动器及文件的信息
Drive()方法根据传入的参数得到 TDriveInfo 信息,根据 TDriveInfo 可以得到 iDriveAtt,iMediaAtt,iType,iBattery 属性,
在 sdk 中查询得到详细说明,进而得到驱动器信息
Volume() 方法可以得到 TVolumeInfo ,这个能得到驱动器的大小及可用空间,名字等信息(名字在模拟器上得不到,不知为什么)
得到一个目录是否存在可以通过下面的代码实现

TInt err=fsSession.MkDir(KMessage3);
if (err!=KErrAlreadyExists) // Don't leave if it already exists
User::LeaveIfError(err);
现在需要解析一个带有全路径的文件该怎么办?
可以使用 TParse 对像,使用 Parse对像时,先要通过 Set 方法去赋于一个全路径的字符串,然后通过 FullName(),Drive(),Path(),Ext(),Name()
分别得到 全名,所在驱动器名,路径,扩展名及名字

请看以下示例

void parseNames(const TDesC& aFileName);
void fileNames()
{
_LIT(KFuncName,"\nDoParsing()\n");
console->Printf(KFuncName);
_LIT(KParse1,"d:\\path\\fn.ext");
parseNames(KParse1);
_LIT(KParse2,"autoexec.bat");
parseNames(KParse2);
_LIT(KParse3,"c:readme");
parseNames(KParse3);
_LIT(KParse4,"c:\\include\\stdio.h");
parseNames(KParse4);
_LIT(KParse5,".prof.ile");
parseNames(KParse5);
_LIT(KParse6,"autoexec.*");
parseNames(KParse6);
}
void parseNames(const TDesC& aFileName)
{
User::LeaveIfError(ifs.Connect());
_LIT(KFullName,"Full name=%S\n");
_LIT(KPathComponents,"Dirve=%S path=%S name=%S ext=%S\n");
_LIT(KFullNameText,"full name against session path=%S\n");
_LIT(KExtension,".txt");
_LIT(KParsePath,"FullName against session path and default extension .txt=%S\n");
TParse p;
User::LeaveIfError(p.Set(aFileName,NULL,NULL));
console->Printf(KFullName,&p.FullName());
TFileName driveName(p.Drive());
TFileName pathname(p.Path());
TFileName filename(p.Name());
TFileName extension(p.Ext());
console->Printf(KPathComponents,&driveName,&pathname,
&filename,&extension);
User::LeaveIfError(ifs.Parse(aFileName,KExtension,p));
console->Printf(KParsePath,&(p.FullName()));
ifs.Close();
}
示例代码来自于 sdk 例子,代码可是我一点点敲上去的

安平2009@原创
qi_jianzhou@126.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: