Symbian Developer Library

SYMBIAN OS V6.1 EDITION FOR C++

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



Using TFindFile

The following example accumulates a list of all the files on any drive which are in a particular directory and which match a name with wildcards, for example, all files matching \System\Fonts\*.gdr.

To do this, it uses TFindFile::FindWildByDir() to begin the search and then uses TFindFile::FindWild() to continue the search on the next drive.

To retrieve the fully qualified path of the matching files, class TParse is used to combine the filename with the drive letter and directory which contains the file.

void ForAllMatchingFiles(RFs& aSession, const TDesC& aWildName, const TDesC& aScanDir)
    {
    TFindFile file_finder(aSession); // 1
    CDir* file_list; // 2
    TInt err = file_finder.FindWildByDir(aWildName,aScanDir, file_list); // 3
    while (err==KErrNone)
        {
        TInt i;
        for (i=0; i<file_list->Count(); i++) // 4
            {
            TParse fullentry;
            fullentry.Set((*file_list)[i].iName,& file_finder.File(),NULL); // 5,6,7
            // Do something with the full EPOC filename
            DoOneFile(aSession, fullentry.FullName()); // 8
            }
        delete file_list; // 9
        err=file_finder.FindWild(file_list); // 10
        }
    }


How to

1. Construct a TFindFile object.

2. FindWildByDir() sets file_list to NULL before assigning values to it, so no memory should be allocated by the caller.

3. This starts the search for matching files. There is considerable flexibility in the handling of aWildName and aScanDir, but the simplest and most common case is where aWildName is the filename and extension (for example, *.gdr) and aScanDir is the directory name, without a drive letter but including a trailing directory separator (for example, \System\Fonts\).

4. CDir is implemented using one of the EPOC array classes, and Count() retrieves the number of items in the list.

5. (*file_list)[i].iName is the name of a file matching the pattern specified (e.g. Eon.gdr).

6. file_finder.File() retrieves the drive and path of the folder containing the files in the CDir, (for example Z:\System\Fonts\).

7. TParse::Set() combines these two components to form a complete filename.

8. TParse::FullName() returns the full filename formed in step 7. The DoOneFile() function can operate on the fully specified filename, (it is assumed that DoOneFile() will need to refer to the file server, so the RFs object is passed to it).

9. FindWildByDir() and FindWildByPath() both allocate the CDir object on your behalf and transfer ownership to the caller. Note that it is your responsibility to delete the CDir object when you have finished with it.

10. Finally, TFindFile::FindWild() continues the search on the next drive in the search sequence.