Symbian
Symbian OS Library

FAQ-0617 How do I actually use TFindFile::FindWildByDir?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Development
Created: 07/03/98 Modified: 12/27/2001
Number: FAQ-0617
Platform: ER5

Question:
I want to accumulate a list of all the files on any drive which are in a particular directory and match a name with
wildcards, for example to find all of the \System\Fonts\*.gdr files. I've managed to work out that I need to use
TFindFile::FindWildByDir, but the documentation gives the impression that the iName in the TEntry objects in the CDir
object would be the full pathname of the file, but actually it's only the name of the file. How can I find out which
drive contains the file?


Answer:
You've found a problem in the C++ SDK Documentation. The drive letter of the current batch of matching entries is available through TFindFile::File(), but in the case of FindWildByDir and FindWildByPath this function only returns the fully qualified name of the directory which contains the supplied files.

Here is some example code:
    void ForAllMatchingFiles(RFs& aSession, const TDesC& aWildName, const TDesC& aScanDir)
    {
    TFindFile search(aSession); // 1
    CDir* dirlist;
    // 2
    TInt err = search.FindWildByDir(aWildname,aScanDir,dirlist);
    // 3
    while (err==KErrNone)
    {

    TInt i;
    for (i=0; iCount(); i++)
    // 4
    {

    TParse fullentry;
    fullentry.Set(&(*dirlist)[i].iName,&search.File(),NULL);
    // 5,6,7
    // Do something with the full EPOC filename
    DoOneFile(aSession, fullentry.FullName()); // 8
    }
    delete dirlist;
    // 9
    err=search.FindWild(dirlist); // more, more!
    // 10
    }

    }
      1. This just creates a TFindFile - it's not yet been configured to do the kind of searching you are asking for.
      2. The value of dirlist is filled in by FindWildByDir, so don't allocate anything.
      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 ("*.gdr" in this example) and aScanDir is the directory name without a drive letter but including a trailing directory separator ("\System\Fonts\" in this example).
      4. The CDir is implemented using one of the EPOC array classes, and Count() tells you how many items there are in the list.
      5. (*dirlist)[i].iName is the actual name of a file matching the "*.gdr" pattern, for example "Eon.gdr"
      6. search.File() is the drive and pathname of the folder containing the file9s) in the CDir, for example "Z:\System\Fonts\"
      7. TParse::Set combines these two things to make a complete name for the file
      8. TParse::FullName() returns the full name of the file computed in the previous step - the DoOneFile function can operate on the fully specified filename (I'm guessing that it will need to talk to the file server, so we pass on the fileserver session object).
      9. FindWildByDir and FindWildByPath both allocate the CDir on your behalf and transfer ownership to the called. It is your responsibility to delete the CDir when you've finished with it - You Have Been Warned.
      10. Finally, TFindFile::FindWild continues the search on the next drive in the search sequence.
      (Added later by DominicP) This example code is now in the C++ SDK, see the documentation of the TFindFile class.