|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept xml:lang="en" id="GUID-CA35A708-C6D9-51D7-873B-A79606FFAF66"><title>How to search for files with TFindFile</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>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 <filepath>\resources\fonts\*.gdr</filepath>. </p> <p>To start a search, use <codeph>TFindFile::FindWildByDir()</codeph>. You can then call <codeph>TFindFile::FindWild()</codeph> to perform the same search on another drive. </p> <p>To retrieve the fully qualified path of the matching files, class <codeph>TParse</codeph> is used to combine the filename with the drive letter and directory which contains the file. The example works as follows: </p> <ol id="GUID-E589950F-603A-5BB3-9387-06D1B2CE2E4B"><li id="GUID-A748895E-D312-505C-A2D7-3C35952F7913"><p>Construct a <codeph>TFindFile</codeph> object. </p> </li> <li id="GUID-A6DE36F9-033A-534B-A27D-A3B8FC50A8D5"><p>Use <codeph>FindWildByDir()</codeph> to start the search for matching files. There is considerable flexibility in the handling of <codeph>aWildName</codeph> and <codeph>aScanDir</codeph>, but the simplest and most common case is where <codeph>aWildName</codeph> is the filename and extension (for example, <filepath>*.gdr</filepath>) and <codeph>aScanDir</codeph> is the directory name, without a drive letter, but including a trailing directory separator (for example, <filepath>\resources\fonts\</filepath>). </p> </li> <li id="GUID-44EE24DB-880F-52A4-85E1-02C575CC6B9F"><p>The list of matching files is returned in a <codeph>CDir</codeph> object, which is implemented as an array. <codeph>Count()</codeph> retrieves the number of items in the list. </p> </li> <li id="GUID-FE931EA6-0AB0-5D5C-88ED-7E4F506DDE60"><p>Use <codeph>file_finder.File()</codeph> to retrieve the drive and path of the folder containing the files in the <codeph>CDir</codeph>, (for example <filepath>Z:\resources\fonts\</filepath>). </p> </li> <li id="GUID-67ACA73A-CDDE-5C95-8B31-4D421BE4D95D"><p>Use <codeph>TParse::Set()</codeph> to combine the file name and path into a full filename. </p> </li> <li id="GUID-B9EEB198-264B-5A82-869D-329077498849"><p>Use <codeph>TFindFile::FindWild()</codeph> to continue the search on the next drive in the search sequence. </p> </li> </ol> <codeblock id="GUID-FECFC563-7050-5A63-B29F-BF757B608818" xml:space="preserve">void ForAllMatchingFiles(RFs& aSession, const TDesC& aWildName, |
|
13 const TDesC& aScanDir) |
|
14 { |
|
15 TFindFile file_finder(aSession); |
|
16 CDir* file_list; |
|
17 TInt err = file_finder.FindWildByDir(aWildname,aScanDir, file_list); |
|
18 while (err==KErrNone) |
|
19 { |
|
20 TInt i; |
|
21 for (i=0; i<file_list->Count(); i++) |
|
22 { |
|
23 TParse fullentry; |
|
24 fullentry.Set((*file_list)[i].iName,& file_finder.File(),NULL); |
|
25 // Do something with the full filename... |
|
26 // ... |
|
27 } |
|
28 delete file_list; |
|
29 err=file_finder.FindWild(file_list); |
|
30 } |
|
31 }</codeblock> <section><title>Notes</title> <ul><li id="GUID-70ACE146-F1EF-50DE-8B9A-C6A7AEAB14A3"><p> <codeph>(*file_list)[i].iName</codeph> is the name of a file matching the pattern specified (e.g. <filepath>Eon.gdr</filepath>). </p> </li> <li id="GUID-F002137B-9501-5552-9B33-09CFF804B922"><p>It is your responsibility to delete the <codeph>CDir</codeph> object when you have finished with it. </p> </li> </ul> </section> </conbody></concept> |