Symbian
Symbian OS Library

SYMBIAN OS V9.3

[Index] [Spacer] [Previous] [Next]



Location: f32file.h
Link against: efsrv.lib

Class TFindFile

class TFindFile;

Description

Searches for files and directories.

Each function has a variant which searches for multiple files/directories, using one or more wildcard characters in the filename. If an initial search is successful, further searches can be carried out using Find() or FindWild(). You can also retrieve the fully qualified file specification, and manipulate and interrogate it using the TParse class (or related classes).

Note that when specifying the path of a directory to search, the path should always end with a backslash character.When trailing backslash is not present then it is considered as file. And path will be taken till last backslash. The client must have appropriate capabilities for the directory to be searched. For example without ALL FILES Capability, it is not possible to successfully find any files under directory.

Members

Defined in TFindFile:
File(), Find(), FindByDir(), FindByPath(), FindWild(), FindWildByDir(), FindWildByPath(), TFindFile()


Construction and destruction


TFindFile()

IMPORT_C TFindFile(RFs &aFs);

Description

Constructor taking a file server session.

Parameters

RFs &aFs

File server session.

[Top]


Member functions


FindByPath()

IMPORT_C TInt FindByPath(const TDesC &aFileName, const TDesC *aPathList);

Description

Searches for a file/directory in one or more directories in the path.

The search ends when the file/directory is found, or when every directory specified in the path list has been unsuccessfully searched.

Notes:

1. For the equivalent search using wildcards, use FindWildByPath().

2. After a file has been found, use TFindFile::File() to get the fully qualified path of the file. To search for the next occurrence, use TFindFile::Find().

Parameters

const TDesC &aFileName

The filename to search for. If this specifies a directory as well as a filename, then that directory is searched first.

const TDesC *aPathList

A list of directories to be searched. Paths in this list must be separated by a semicolon character, but a semicolon is not required after the final path. The directories are searched in the order in which they occur in the list. If a path in the list contains a drive letter, that drive alone is searched. If a path contains no drive letter, the function searches for the file in that directory on every available drive in turn, beginning with drive Y:, in descending alphabetical order and ending with drive Z:.When path is empty then session path will be used for the search.

Return value

TInt

KErrNone, if the filename was found; KErrNotFound, if the filename was not found. KErrArgument, if the filename is empty.


FindByDir()

IMPORT_C TInt FindByDir(const TDesC &aFileName, const TDesC &aDirPath);

Description

Searches for a file/directory in a directory on all available drives.

The search ends when the file/directory is found, or when every available drive has been unsuccessfully searched.

Notes:

1. A drive letter may be specified in aDirPath. If a drive is specified, then that drive is searched first. If no drive is specified, then the drive specified in the session path is searched first. The remaining available drives are then searched in descending alphabetical order, from Y: to A:, and ending with the Z: drive.

2. For the corresponding search using wildcards, use FindWildByDir().

3. After a file has been found, use TFindFile::File() to get the fully qualified path and filename. To search for the next occurrence, use TFindFile::Find().

Parameters

const TDesC &aFileName

The filename to search for. If a path is specified, it overrides the path specified in aDir. If no path is specified, the path contained in aDir is used.

const TDesC &aDirPath

A single path indicating a directory to be searched on each drive.When path is empty then session path will be used for the search.

Return value

TInt

KErrNone, if the file was found, otherwise one of the system-wide error codes, including: KErrNotFound, if the file was not found; KErrPermissionDenied, if the client does not have appropriate capabilities for the directory to be searched; KErrArgument, if the filename is empty.

See also:


Find()

IMPORT_C TInt Find();

Description

Searches for the next file/directory.

This should be used after a successful call to FindByPath() or FindByDir(), to find the next occurrence of the filename in the path or drive list.

Note:

1. After a file/directory has been found, use TFindFile::File() to get the fully qualified path and filename.

Return value

TInt

KErrNone, if another occurrence of the file was found; KErrNotFound, if no more occurrences were found.


FindWildByPath()

IMPORT_C TInt FindWildByPath(const TDesC &aFileName, const TDesC *aPathList, CDir *&aDirList);

Description

Searches for one or more files/directories in the directories contained in a path list.

Wildcard characters can be specified. The search ends when one or more filenames matching aFileName is found, or when every directory in the path list has been unsuccessfully searched. To begin searching again after a successful match has been made, use FindWild().

Notes:

1. The caller of the function is responsible for deleting aDir after the function has returned.

2. Calling TFindFile::File() after a successful search gets the drive letter and directory containing the file(s). The filenames can be retrieved via the array of TEntry::iName objects contained in aDir. If you want to retrieve the fully qualified path of a file, you need to parse the path and the filename.

Parameters

const TDesC &aFileName

The filename to search for. May contain wildcards. If it specifies a directory as well as a filename, then that directory is searched first.

const TDesC *aPathList

List of directories to search. Paths in this list must be separated by a semicolon character, but a semicolon is not required after the final path. The directories are searched in the order in which they occur in the list. Directories must be fully qualified, including a drive letter, and the name must end with a backslash.

CDir *&aDirList

On return, contains the entries for all files matching aFileName in the first directory in which a match occurred.

Return value

TInt

KErrNone, if one or more matching files was found; KErrNotFound, if no matching file was found in any of the directories. KErrArgument, if the filename is empty.

See also:


FindWildByDir()

IMPORT_C TInt FindWildByDir(const TDesC &aFileName, const TDesC &aDirPath, CDir *&aDir);

Description

Searches, using wildcards, for one or more files/directories in a specified directory.

If no matching file is found in that directory, all available drives are searched in descending alphabetical order, from Y: to A:, and ending with the Z: drive.

The search ends when one or more matching filenames are found, or when every available drive has been unsuccessfully searched. To begin searching again after a successful match has been made, use FindWild(). Wildcards may be specified in the filename.

Notes:

1. A drive letter may be specified in aDirPath (or in aFileName). If a drive is specified, that drive is searched first, followed by the other available drives, in descending alphabetical order. If no drive is specified, the drive contained in the session path is searched first.

2. The function sets aDir to NULL, then allocates memory for it before appending entries to the list. Therefore, aDir should have no memory allocated to it before this function is called, otherwise this memory will become orphaned.

3. The caller of this function is responsible for deleting aDir after the function has returned.

4. Calling TFindFile::File() after a successful search returns the drive letter and directory containing the file(s). Filenames may be retrieved via the array of TEntry::iNames contained in aDir. If you want to retrieve the fully qualified path of a file, you will need to parse the path and the filename.

Parameters

const TDesC &aFileName

The filename to search for. May contain wildcards. If a path is specified, it overrides the path specified in aDirPath. If no path is specified, the path contained in aDirPath is used in the search.

const TDesC &aDirPath

Path indicating a directory to search on each drive.

CDir *&aDir

On return, contains the entries for all files matching aFileName.

Return value

TInt

KErrNone if one or more matching files was found; KErrNotFound if no matching file was found in the directory on any of the drives. KErrArgument, if the filename is empty.


FindWild()

IMPORT_C TInt FindWild(CDir *&aDirList);

Description

Searches for the next file/directory.

This should be used after a successful call to FindWildByPath() or FindWildByDir(), for the next occurrences of the filename in the path or drive list.

Notes:

1. The caller of this function is responsible for deleting aDir after the function has returned

2. Calling TFindFile::File() after a successful search, will return the drive letter and the directory containing the file(s). The filenames may be retrieved via the array of TEntry::iName objects contained in aDir. If you want to retrieve the fully qualified path of a file, you will need to parse the path and the filename using the TParse class or derived classes.

Parameters

CDir *&aDirList

On return, contains the entries for all matching files found in the next directory.

Return value

TInt

KErrNone, if further occurrences were found; KErrNotFound, if no more matching files were found.

See also:


File()

inline const TDesC &File() const;

Description

Gets the full file specification of a file which was found by a successful call to any of the search variants that do not accept wildcards.

The file specification includes drive, path and filename.

Notes:

1. When called after a successful search using wildcards the only valid components of the retrieved file specification are drive letter and directory.

Return value

const TDesC &

The full path and filename.