diff -r 43e37759235e -r 51a74ef9ed63 Symbian3/SDK/Source/GUID-CA35A708-C6D9-51D7-873B-A79606FFAF66.dita --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Symbian3/SDK/Source/GUID-CA35A708-C6D9-51D7-873B-A79606FFAF66.dita Wed Mar 31 11:11:55 2010 +0100 @@ -0,0 +1,71 @@ + + + + + +How +to search for files with TFindFileThis topic provides an example on how to search for files with +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 \resources\fonts\*.gdr.

+

To start a search, use TFindFile::FindWildByDir(). You +can then call TFindFile::FindWild() to perform the same search +on another 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. The example works as follows:

+
    +
  1. Construct a TFindFile object.

  2. +
  3. Use FindWildByDir() to +start 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, \resources\fonts\).

  4. +
  5. The list of matching +files is returned in a CDir object, which is implemented +as an array. Count() retrieves the number of items in the +list.

  6. +
  7. Use file_finder.File() to +retrieve the drive and path of the folder containing the files in the CDir, +(for example Z:\resources\fonts\).

  8. +
  9. Use TParse::Set() to +combine the file name and path into a full filename.

  10. +
  11. Use TFindFile::FindWild() to +continue the search on the next drive in the search sequence.

  12. +
+void ForAllMatchingFiles(RFs& aSession, const TDesC& aWildName, + const TDesC& aScanDir) + { + TFindFile file_finder(aSession); + CDir* file_list; + TInt err = file_finder.FindWildByDir(aWildname,aScanDir, file_list); + while (err==KErrNone) + { + TInt i; + for (i=0; i<file_list->Count(); i++) + { + TParse fullentry; + fullentry.Set((*file_list)[i].iName,& file_finder.File(),NULL); + // Do something with the full filename... + // ... + } + delete file_list; + err=file_finder.FindWild(file_list); + } + } +
Notes
    +
  • (*file_list)[i].iName is +the name of a file matching the pattern specified (e.g. Eon.gdr).

  • +
  • It is your responsibility +to delete the CDir object when you have finished with it.

  • +
+
\ No newline at end of file