Obtain the file path information TParse.

Source: Internet
Author: User

Obtain the file path information TParse.

The driver information can be obtained based on DriveList and Drive methods.

  • DriveList requires the CDir object to save the list. Every data in the CDir object is of the TEntry type. Therefore, the drive and file information can be obtained based on TEntry.
  • The Drive () method obtains TDriveInfo information based on the input parameters, and obtains the iDriveAtt, iMediaAtt, iType, and iBattery Attributes Based on TDriveInfo,
    Query the driver information in the sdk for detailed instructions.
  • The Volume () method can get TVolumeInfo, which can get the drive size, available space, name and other information (the name is not available on the simulator, I do not know why)
  • To check whether a directory exists, use the following code:
    TInt err = fsSession. MkDir (KMessage3 );
    If (err! = KErrAlreadyExists) // Don't leave if it already exists
    User: LeaveIfError (err );

What should I do if I need to parse a file with a full path?
You can use the TParse object. When using the Parse object, you must first use the Set method to assign a full Path string, and then use FullName (), Drive (), Path (), ext (), Name ()
Obtain the full name, drive name, path, extension, and name respectively.

See the following example.

Void parseNames (const TDesC & aFileName );
Void fileNames ()
{
_ Annotate (KFuncName, "\ nDoParsing () \ n ");
Console-> Printf (KFuncName );
_ Partition (KParse1, "d: \ path \ fn. ext ");
ParseNames (KParse1 );
_ Partition (KParse2, "autoexec. bat ");
ParseNames (KParse2 );
_ Commit (KParse3, "c: readme ");
ParseNames (KParse3 );
_ Partition (KParse4, "c: \ include \ stdio. h ");
ParseNames (KParse4 );
_ Partition (KParse5, ". prof. ile ");
ParseNames (KParse5 );
_ Partition (KParse6, "autoexec .*");
ParseNames (KParse6 );
}
Void parseNames (const TDesC & aFileName)
{
User: LeaveIfError (ifs. Connect ());
_ Annotate (KFullName, "Full name = % S \ n ");
_ Partition (KPathComponents, "Dirve = % S path = % S name = % S ext = % S \ n ");
_ Resolve (KFullNameText, "full name against session path = % S \ n ");
_ Partition (KExtension, ". txt ");
_ Partition (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 ();
}

The sample code is from the sdk example.

 

Anping 2009 @ original
Qi_jianzhou@126.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.