Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

[Index] [Glossary] [Previous] [Next]



Using TParse


Retrieving individual components

The following code fragment shows how the individual components are extracted using the TParseBase functions:

_LIT(KPath,"c:\\wrd\\meeting.wrd");
...
TParse p;
p.Set(KPath,NULL,NULL);
p.Name(); // gives "meeting"
p.NameAndExt(); // gives "meeting.wrd"
...

[Top]


Component masking

TParse can be used to select components from different file and path specifications. The Set() function takes three arguments. They are each parsed into four components: drive, path, filename and extension.

The example below sets up the TParse object so that it can be used to yield useful information.

_LIT(KSpec,"A:file1");
_LIT(KRelated,"C:\\path1\\related.xxx");
TParse fp;
fp.Set(KSpec,&KRelated,NULL);

drive

path

filename

extension

file specification

A:

file1

related name

C:

\path1\

related

.xxx

default name

result

A:

\path1\

file1

.xxx

The resulting fp.fullname will be A:\path1\file1.xxx. All the components that are specified in the file specification (drive and filename) are put into the result; any missing components (path and extension) are taken from the related file specification which has next order of precedence; nothing is specified in the default.

The second example shows how wildcards are allowed in the filename and extension.

TParse fp;
    _LIT(KSpec,"A:file1");
    _LIT(KDefault,"C:\\path1\\*.*");
    fp.Set(KSpec,NULL,&KDefault);

drive

path

filename

extension

file specification

A:

file1

related filename

default filename

C:

\path1\

*

.*

result

A:

\path1\

file1

.*

The resulting fp.fullname will be A:\path1\file1.*


Parsing with reference to the session default directory

TParse operations occur without reference to the file server. Two RFs::Parse() functions perform a TParse::Set() using the session path as the aDefault argument — one of these variants specifies an aRelated, the other does not. Use these RFs::Parse() functions to parse filenames with reference to the session path.

[Top]


Wildcard characters

The ? and * wildcard characters are supported to indicate a single character, and any sequence of characters. Both wildcard characters can be used any number of times in any part of any component of the file specification, except the drive. Although there is no intention that these will ever change, they are defined as the constants KMatchOne and KMatchAny.

[Top]


Illegal paths

The following restrictions apply to path components. If any are violated, TParse will return KErrBadName:

_LIT(KText,"DIR\\");
...
TInt r=parse.Set(KText,NULL,NULL);

_LIT(KBadText,"C: \\DIR\\");
...
r=parse.Set(KBadText,NULL,NULL);