os/kernelhwsrv/userlibandfileserver/fileserver/sfsrv/cl_find.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// f32\sfsrv\cl_find.cpp
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include "cl_std.h"
sl@0
    19
sl@0
    20
#define gPathDelimiter TChar(';')
sl@0
    21
enum TMode {EFindByDrives,EFindByDrivesInPath,EFindByPath};
sl@0
    22
sl@0
    23
TInt TFindFile::DoFindInDir()
sl@0
    24
//
sl@0
    25
// Look for aFileName in aDir
sl@0
    26
//
sl@0
    27
	{
sl@0
    28
sl@0
    29
	if (iDir==NULL)
sl@0
    30
		{
sl@0
    31
		TEntry entry;
sl@0
    32
		TInt r=iFs->Entry(iFile.FullName(),entry);
sl@0
    33
		if (r==KErrNone /*|| r==KErrAccessDenied*/)
sl@0
    34
			return(KErrNone);
sl@0
    35
		else if (r==KErrNoMemory)
sl@0
    36
			return r;
sl@0
    37
		else if (r==KErrPermissionDenied)
sl@0
    38
			return (KErrPermissionDenied);
sl@0
    39
		else
sl@0
    40
			return(KErrNotFound);
sl@0
    41
		}
sl@0
    42
	TInt r=iFs->GetDir(iFile.FullName(),KEntryAttMaskSupported|KEntryAttAllowUid,ESortByName,*iDir);
sl@0
    43
	if (r==KErrNoMemory)
sl@0
    44
		return r;
sl@0
    45
	else if (r==KErrPermissionDenied)
sl@0
    46
		return r;
sl@0
    47
	else if (r!=KErrNone)
sl@0
    48
		return(KErrNotFound);
sl@0
    49
	if ((*iDir)->Count()==0)
sl@0
    50
		{
sl@0
    51
		delete (*iDir);
sl@0
    52
		*iDir=NULL;
sl@0
    53
		return(KErrNotFound);
sl@0
    54
		}
sl@0
    55
	else
sl@0
    56
		return(KErrNone);
sl@0
    57
	}
sl@0
    58
sl@0
    59
TInt TFindFile::DoFindNextInPath()
sl@0
    60
//
sl@0
    61
// Look for aFileName along the path and increment aPathPos
sl@0
    62
//
sl@0
    63
	{
sl@0
    64
sl@0
    65
	if (iMode==EFindByDrivesInPath)
sl@0
    66
		{
sl@0
    67
		TInt r=DoFindNextInDriveList();
sl@0
    68
		if (r==KErrNone)
sl@0
    69
			return(KErrNone);
sl@0
    70
		if (r!=KErrNotFound)
sl@0
    71
			return(r);
sl@0
    72
		iMode=EFindByPath;
sl@0
    73
		}
sl@0
    74
	FOREVER
sl@0
    75
		{
sl@0
    76
		if (iPath->Length()<iPathPos)
sl@0
    77
			return(KErrNotFound);
sl@0
    78
		TPtrC path(iPath->Ptr()+iPathPos,iPath->Length()-iPathPos);
sl@0
    79
		TInt r=path.Locate(gPathDelimiter);
sl@0
    80
		if (r==KErrNotFound)
sl@0
    81
			r=path.Length();
sl@0
    82
		path.Set(path.Ptr(),r);
sl@0
    83
		iPathPos+=r+1;
sl@0
    84
		TFileName fileName=iFile.NameAndExt();
sl@0
    85
		iFile.Set(fileName,&path,NULL);
sl@0
    86
		if (iFile.FullName().Length()>=2 && iFile.FullName()[1]==KDriveDelimiter)
sl@0
    87
			{
sl@0
    88
			TInt r=DoFindInDir();
sl@0
    89
			if (r==KErrNone)
sl@0
    90
				return(KErrNone);
sl@0
    91
			if (r!=KErrNotFound)
sl@0
    92
				return(r);
sl@0
    93
			continue;
sl@0
    94
			}
sl@0
    95
		iMode=EFindByDrivesInPath;
sl@0
    96
		
sl@0
    97
		r=FindByDir(fileName,path);
sl@0
    98
		if (r==KErrNone)
sl@0
    99
			return(KErrNone);
sl@0
   100
		if (r!=KErrNotFound)
sl@0
   101
			return(r);
sl@0
   102
		}
sl@0
   103
sl@0
   104
	}
sl@0
   105
sl@0
   106
TInt TFindFile::DoFindNextInDriveList()
sl@0
   107
//
sl@0
   108
// Look for aFileName in all available drives in order
sl@0
   109
//
sl@0
   110
	{
sl@0
   111
	
sl@0
   112
	TInt found;	
sl@0
   113
	TDriveInfo driveInfo;
sl@0
   114
	const TUint matchedFlags= iMatchMask & KDriveAttMatchedFlags;  //KDriveAttMatchedFlags = 0xFFF
sl@0
   115
	const TUint matchedAtt = iMatchMask & KDriveAttMatchedAtt;	 //KDriveAttMatchedAtt = 0x0FFF0000
sl@0
   116
	
sl@0
   117
	if (iMatchMask == (KDriveAttExclude | KDriveAttMatchedFlags ) ) //If all drives are excluded.
sl@0
   118
		return KErrNotFound;
sl@0
   119
sl@0
   120
	FOREVER
sl@0
   121
		{
sl@0
   122
				
sl@0
   123
		found =0;
sl@0
   124
		TInt currentDrive=iCurrentDrive;
sl@0
   125
		
sl@0
   126
		
sl@0
   127
		if (iCurrentDrive==-1)
sl@0
   128
			currentDrive=EDriveZ;
sl@0
   129
			
sl@0
   130
		
sl@0
   131
		if (currentDrive<=-2)
sl@0
   132
			return(KErrNotFound);	
sl@0
   133
			
sl@0
   134
				
sl@0
   135
		iCurrentDrive--;
sl@0
   136
sl@0
   137
		if (!iDrvList[currentDrive])
sl@0
   138
			continue;
sl@0
   139
sl@0
   140
		TInt err = iFs->Drive(driveInfo,currentDrive);
sl@0
   141
sl@0
   142
		if(iMatchMask == 0)
sl@0
   143
			{
sl@0
   144
			if (iDrvList[currentDrive] & KDriveAttRemote)
sl@0
   145
				continue;									// NOT allowed on REMOTE DRIVE
sl@0
   146
			if ((iDrvList[currentDrive] & (KDriveAttLocal|KDriveAttRom))==0)
sl@0
   147
				continue;
sl@0
   148
			}
sl@0
   149
		else 	
sl@0
   150
			{									
sl@0
   151
 
sl@0
   152
			if(matchedFlags != 0 )
sl@0
   153
				{
sl@0
   154
sl@0
   155
				switch(matchedAtt)
sl@0
   156
					{ //found ==0 means that this drive attributes didn't match the flags
sl@0
   157
					
sl@0
   158
					case KDriveAttExclude :
sl@0
   159
						found = (driveInfo.iDriveAtt & matchedFlags ) ? 0:iDrvList[currentDrive] ;
sl@0
   160
						break;
sl@0
   161
sl@0
   162
					case 0:
sl@0
   163
						found = (driveInfo.iDriveAtt & matchedFlags) ? iDrvList[currentDrive]:0 ;
sl@0
   164
						break;
sl@0
   165
sl@0
   166
sl@0
   167
					case KDriveAttExclusive :
sl@0
   168
						if(matchedFlags != KDriveAttLogicallyRemovable)
sl@0
   169
							{
sl@0
   170
sl@0
   171
							found = ((TUint8)(driveInfo.iDriveAtt) == matchedFlags)  ?iDrvList[currentDrive]:0;
sl@0
   172
								
sl@0
   173
							}
sl@0
   174
						else 
sl@0
   175
							{
sl@0
   176
							found = (driveInfo.iDriveAtt == (matchedFlags | KDriveAttRemovable) )  ?iDrvList[currentDrive]:0;
sl@0
   177
							}
sl@0
   178
						
sl@0
   179
						break;
sl@0
   180
sl@0
   181
					case KDriveAttExclude | KDriveAttExclusive:
sl@0
   182
						if(matchedFlags != KDriveAttLogicallyRemovable)
sl@0
   183
							{
sl@0
   184
						
sl@0
   185
							found = ((TUint8)(driveInfo.iDriveAtt) == matchedFlags)  ?0:iDrvList[currentDrive];
sl@0
   186
								
sl@0
   187
							}
sl@0
   188
						else 
sl@0
   189
							{
sl@0
   190
							found = (driveInfo.iDriveAtt == (matchedFlags | KDriveAttRemovable))  ?0:iDrvList[currentDrive];
sl@0
   191
							}
sl@0
   192
						
sl@0
   193
						break;
sl@0
   194
sl@0
   195
					default: 
sl@0
   196
						Panic(EFindFileIllegalAttribute);			
sl@0
   197
							
sl@0
   198
					}
sl@0
   199
				}
sl@0
   200
sl@0
   201
			else  //matchedFlags == 0.
sl@0
   202
				{
sl@0
   203
				
sl@0
   204
				if (matchedAtt== KDriveAttAll)		
sl@0
   205
					found= iDrvList[currentDrive];
sl@0
   206
				else 
sl@0
   207
					Panic(EFindFileIllegalAttribute);		
sl@0
   208
									
sl@0
   209
				}
sl@0
   210
			
sl@0
   211
		
sl@0
   212
		
sl@0
   213
			if( found == 0)
sl@0
   214
				continue;			
sl@0
   215
sl@0
   216
			}
sl@0
   217
		
sl@0
   218
		// Don't scan a locked drive
sl@0
   219
		
sl@0
   220
		if( err == KErrNone)
sl@0
   221
			{		
sl@0
   222
			if(driveInfo.iMediaAtt & KMediaAttLocked)
sl@0
   223
				continue;
sl@0
   224
			}
sl@0
   225
		
sl@0
   226
sl@0
   227
		TParse fileName;
sl@0
   228
		TChar driveLetter;
sl@0
   229
		RFs::DriveToChar(currentDrive,driveLetter);
sl@0
   230
		TBuf<4> drive;
sl@0
   231
		drive.SetLength(2);
sl@0
   232
		drive[0]=(TText)driveLetter;
sl@0
   233
		drive[1]=':';
sl@0
   234
		TPtrC nameAndExt(iFile.NameAndExt());
sl@0
   235
		TPtrC path(iFile.Path());
sl@0
   236
		fileName.Set(nameAndExt,&path,&drive);
sl@0
   237
		iFile=fileName;
sl@0
   238
		TInt r=DoFindInDir();
sl@0
   239
		if (r==KErrNone)
sl@0
   240
			return(KErrNone);
sl@0
   241
		if (r!=KErrNotFound)
sl@0
   242
			return(r);
sl@0
   243
		}	
sl@0
   244
	}
sl@0
   245
sl@0
   246
sl@0
   247
sl@0
   248
sl@0
   249
EXPORT_C TFindFile::TFindFile(RFs& aFs)
sl@0
   250
	: iFs(&aFs), iPathPos(0), iCurrentDrive(0), iMode(-1), iMatchMask(0)
sl@0
   251
/**
sl@0
   252
Constructor taking a file server session.
sl@0
   253
sl@0
   254
@param aFs File server session.
sl@0
   255
*/
sl@0
   256
	{
sl@0
   257
	
sl@0
   258
	iFile.Set(_L(""),NULL,NULL);
sl@0
   259
	}
sl@0
   260
sl@0
   261
sl@0
   262
sl@0
   263
sl@0
   264
TInt TFindFile::DoFindByPath(const TDesC& aFileName,const TDesC* aPath)
sl@0
   265
//
sl@0
   266
// Look for a file in each directory in the path
sl@0
   267
// Make initial check for aFileName in the current directory
sl@0
   268
//
sl@0
   269
	{
sl@0
   270
	
sl@0
   271
	if (aFileName.Length() <= 0) 
sl@0
   272
		return(KErrArgument);
sl@0
   273
	
sl@0
   274
	TInt r=iFile.Set(aFileName,NULL,NULL);
sl@0
   275
	if (r!=KErrNone)
sl@0
   276
		return(r);
sl@0
   277
	iPath=aPath;
sl@0
   278
	iPathPos=0;
sl@0
   279
	iMode=EFindByPath;
sl@0
   280
	r=DoFindInDir();	
sl@0
   281
	
sl@0
   282
	
sl@0
   283
	if (r==KErrNone)
sl@0
   284
		return(KErrNone);
sl@0
   285
	if (r!=KErrNotFound)
sl@0
   286
		return(r);
sl@0
   287
	if ((iPath==NULL) || (iPath->Length()==0))
sl@0
   288
		return(KErrNotFound);
sl@0
   289
	
sl@0
   290
	
sl@0
   291
	r=DoFindNextInPath();
sl@0
   292
	return(r);
sl@0
   293
	}
sl@0
   294
sl@0
   295
TInt TFindFile::DoFindByDir(const TDesC& aFileName,const TDesC& aDir)
sl@0
   296
//
sl@0
   297
// Look for aFileName in aDir on each connected drive
sl@0
   298
// Make initial check for aFileName in aDir on current drive
sl@0
   299
//
sl@0
   300
	{
sl@0
   301
		
sl@0
   302
	if (aFileName.Length() <= 0) 
sl@0
   303
		return(KErrArgument);
sl@0
   304
sl@0
   305
	TInt r=iFs->Parse(aFileName,aDir,iFile);
sl@0
   306
	if (r!=KErrNone)
sl@0
   307
		return(r);
sl@0
   308
	TInt searchResult=DoFindInDir();
sl@0
   309
	if(searchResult==KErrNoMemory)                       
sl@0
   310
		return(searchResult);
sl@0
   311
	
sl@0
   312
	if(searchResult==KErrPermissionDenied)
sl@0
   313
		return (KErrPermissionDenied);
sl@0
   314
	
sl@0
   315
	r=iFs->DriveList(iDrvList,KDriveAttAll);
sl@0
   316
	if (r!=KErrNone)
sl@0
   317
		return(r);
sl@0
   318
	TInt drive;
sl@0
   319
	r=RFs::CharToDrive(iFile.Drive()[0],drive);
sl@0
   320
	if (r!=KErrNone)
sl@0
   321
		return(r);
sl@0
   322
	iDrvList[drive]=0; // Drive 'drive' has already been searched
sl@0
   323
	iCurrentDrive=EDriveY;
sl@0
   324
	iMode=EFindByDrives;
sl@0
   325
	if (searchResult==KErrNone)
sl@0
   326
		return(KErrNone);
sl@0
   327
	
sl@0
   328
	
sl@0
   329
	return(DoFindNextInDriveList());
sl@0
   330
	}
sl@0
   331
sl@0
   332
sl@0
   333
sl@0
   334
sl@0
   335
EXPORT_C TInt TFindFile::FindByPath(const TDesC& aFileName,const TDesC* aPath)
sl@0
   336
/**
sl@0
   337
Searches for a file/directory in one or more directories in the path.
sl@0
   338
sl@0
   339
The search ends when the file/directory is found, or when every directory
sl@0
   340
specified in the path list has been unsuccessfully searched.
sl@0
   341
sl@0
   342
Notes:
sl@0
   343
	
sl@0
   344
1. For the equivalent search using wildcards, use FindWildByPath().
sl@0
   345
sl@0
   346
2. After a file has been found, use TFindFile::File() to get the fully qualified path of the file. To
sl@0
   347
   search for the next occurrence, use TFindFile::Find().
sl@0
   348
sl@0
   349
@param aFileName The filename to search for. If this specifies a directory as well
sl@0
   350
                 as a filename, then that directory is searched first.
sl@0
   351
@param aPath     A list of directories to be searched. Paths in this list must
sl@0
   352
                 be separated by a semicolon character, but a semicolon is not
sl@0
   353
                 required after the	final path. The directories are searched in
sl@0
   354
                 the order in which they occur in the list. If a path in
sl@0
   355
                 the list contains a drive letter, that drive alone is searched.
sl@0
   356
                 If a path contains no drive letter, the function searches for
sl@0
   357
                 the file in that directory on every available drive in turn,
sl@0
   358
                 beginning with drive Y:, in descending alphabetical order
sl@0
   359
                 and ending with drive Z:.When path is empty then session path 
sl@0
   360
                 will be used for the search.
sl@0
   361
sl@0
   362
@return KErrNone, if the filename was found;
sl@0
   363
        KErrNotFound, if the filename was not found.
sl@0
   364
        KErrArgument, if the filename is empty. 
sl@0
   365
sl@0
   366
@see TFindFile::FindWildByPath
sl@0
   367
@see TFindFile::File
sl@0
   368
@see TFindFile::Find
sl@0
   369
*/
sl@0
   370
	{
sl@0
   371
sl@0
   372
	iDir=NULL;
sl@0
   373
	return(DoFindByPath(aFileName,aPath));
sl@0
   374
	}
sl@0
   375
sl@0
   376
sl@0
   377
sl@0
   378
sl@0
   379
EXPORT_C TInt TFindFile::FindByDir(const TDesC& aFileName,const TDesC& aDir)
sl@0
   380
/**
sl@0
   381
Searches for a file/directory in a directory on all available drives.
sl@0
   382
sl@0
   383
The	search ends when the file/directory is found, or when every available
sl@0
   384
drive has been unsuccessfully searched.
sl@0
   385
sl@0
   386
Notes:
sl@0
   387
sl@0
   388
1. A drive letter may be specified in aDirPath.
sl@0
   389
   If a drive is specified, then that drive is searched first. If no drive is
sl@0
   390
   specified, then the drive specified in the session path is searched first.
sl@0
   391
   The remaining available drives are then searched in descending alphabetical
sl@0
   392
   order, from Y: to A:, and ending with the Z: drive. Using function SetFindMask
sl@0
   393
   it is possible to specify a combination of attributes that the drives to be 
sl@0
   394
   searched must match.
sl@0
   395
   
sl@0
   396
sl@0
   397
2. For the corresponding search using wildcards, use FindWildByDir().
sl@0
   398
sl@0
   399
3. After a file has been found, use TFindFile::File() to get the fully
sl@0
   400
   qualified path and filename. To search for the next occurrence,
sl@0
   401
   use TFindFile::Find().
sl@0
   402
sl@0
   403
@param aFileName The filename to search for. If a path is specified, it
sl@0
   404
                 overrides the path specified in aDir. If no path is specified,
sl@0
   405
                 the path contained in aDir is used.
sl@0
   406
@param aDir      A single path indicating a directory to be searched on each
sl@0
   407
                 drive.When path is empty then session path will be used for the search.
sl@0
   408
sl@0
   409
@return KErrNone, if the file was found, otherwise one of the system-wide error codes, including:
sl@0
   410
        KErrNotFound, if the file was not found;
sl@0
   411
        KErrPermissionDenied, if the client does not have appropriate capabilities for the directory to be searched;
sl@0
   412
		KErrArgument, if the filename is empty.
sl@0
   413
sl@0
   414
@see TFindFile::FindWildByDir()
sl@0
   415
@see TFindFile::File()
sl@0
   416
@see TFindFile::Find()
sl@0
   417
@see TFindFile::SetFindMask()
sl@0
   418
*/
sl@0
   419
	{
sl@0
   420
sl@0
   421
	iDir=NULL;
sl@0
   422
	return(DoFindByDir(aFileName,aDir));
sl@0
   423
	}
sl@0
   424
sl@0
   425
sl@0
   426
sl@0
   427
sl@0
   428
EXPORT_C TInt TFindFile::FindWildByPath(const TDesC& aFileName,const TDesC* aPath,CDir*& aDir)
sl@0
   429
/**
sl@0
   430
Searches for one or more files/directories in the directories contained in a
sl@0
   431
path list.
sl@0
   432
sl@0
   433
Wildcard characters can be specified. The search ends when one or more
sl@0
   434
filenames matching aFileName is found, or when every
sl@0
   435
directory in the path list has been unsuccessfully searched.
sl@0
   436
To begin searching again after a successful match has been made,
sl@0
   437
use FindWild().
sl@0
   438
sl@0
   439
Using function SetFindMask it is possible to specify a combination of 
sl@0
   440
attributes that the drives to be searched must match.
sl@0
   441
sl@0
   442
Notes:
sl@0
   443
sl@0
   444
1. The caller of the function is responsible for deleting
sl@0
   445
   aDir after the function has returned.
sl@0
   446
sl@0
   447
2. Calling TFindFile::File() after a successful search gets the drive letter
sl@0
   448
   and directory containing the file(s). The filenames can be retrieved via
sl@0
   449
   the array of TEntry::iName objects contained in aDir. If you want to
sl@0
   450
   retrieve the fully qualified path of a file, you need to parse the path and
sl@0
   451
   the filename.
sl@0
   452
   
sl@0
   453
@param aFileName The filename to search for. May contain wildcards. If
sl@0
   454
                 it specifies a directory as well as a filename, then that
sl@0
   455
                 directory is searched first.
sl@0
   456
@param aPath     List of directories to search. Paths in this list must be
sl@0
   457
                 separated by a semicolon character, but a semicolon is not
sl@0
   458
                 required after the final path. The directories are searched
sl@0
   459
                 in the order in which they occur in the list.
sl@0
   460
                 Directories must be fully qualified, including
sl@0
   461
                 a drive letter, and the name must end with a backslash.
sl@0
   462
@param aDir      On return, contains the entries for all files matching
sl@0
   463
				 aFileName in the first directory in which a match occurred.
sl@0
   464
sl@0
   465
@return KErrNone, if one or more matching files was	found;
sl@0
   466
        KErrNotFound, if no matching file was found in any of the directories.
sl@0
   467
        KErrArgument, if the filename is empty.
sl@0
   468
sl@0
   469
@see TFindFile::FindWild
sl@0
   470
@see TFindFile::File
sl@0
   471
@see TEntry::iName
sl@0
   472
@see TFindFile::SetFindMask()
sl@0
   473
*/
sl@0
   474
	{
sl@0
   475
sl@0
   476
	iDir=&aDir;
sl@0
   477
	return(DoFindByPath(aFileName,aPath));
sl@0
   478
	}
sl@0
   479
sl@0
   480
sl@0
   481
sl@0
   482
sl@0
   483
EXPORT_C TInt TFindFile::FindWildByDir(const TDesC& aFileName,const TDesC& aDirPath,CDir*& aDir)
sl@0
   484
/**
sl@0
   485
Searches, using wildcards, for one or more files/directories in a specified
sl@0
   486
directory.
sl@0
   487
sl@0
   488
If no matching file is found in that directory, all available drives are
sl@0
   489
searched in descending alphabetical order, from Y: to A:, and ending
sl@0
   490
with the Z: drive.Using function SetFindMask it is possible to specify a 
sl@0
   491
combination of attributes that the drives to be searched must match.
sl@0
   492
sl@0
   493
The search ends when one or more matching filenames are found, or when every 
sl@0
   494
available drive has been unsuccessfully searched. To begin searching again 
sl@0
   495
after a successful match has been made, use FindWild(). Wildcards may be
sl@0
   496
specified in the filename.
sl@0
   497
sl@0
   498
Notes:
sl@0
   499
sl@0
   500
1. A drive letter may be specified in aDirPath (or in aFileName). If a drive 
sl@0
   501
   is specified, that drive is searched first, followed by the other available 
sl@0
   502
   drives, in descending alphabetical order. If no drive is specified, the drive 
sl@0
   503
   contained in the session path is searched first.
sl@0
   504
sl@0
   505
2. The function sets aDir to NULL, then allocates memory for it before appending 
sl@0
   506
   entries to the list. Therefore, aDir should have no memory allocated to it 
sl@0
   507
   before this function is called, otherwise this memory will become orphaned.
sl@0
   508
sl@0
   509
3. The caller of this function is responsible for deleting aDir after the function 
sl@0
   510
   has returned.
sl@0
   511
sl@0
   512
4. Calling TFindFile::File() after a successful search returns the drive letter 
sl@0
   513
   and directory containing the file(s). Filenames may be retrieved via the array 
sl@0
   514
   of TEntry::iNames contained in aDir. If you want to retrieve the fully 
sl@0
   515
   qualified path of a file, you will need to parse the path and the filename.
sl@0
   516
sl@0
   517
@param aFileName The filename to search for. May contain wildcards. If a path 
sl@0
   518
                 is specified, it overrides the path specified in aDirPath.
sl@0
   519
                 If no path is specified, the path contained in aDirPath is
sl@0
   520
                 used in the search.
sl@0
   521
@param aDirPath  Path indicating a directory to search on each drive.
sl@0
   522
@param aDir      On return, contains the entries for all files
sl@0
   523
                 matching aFileName.
sl@0
   524
                 
sl@0
   525
@return KErrNone if one or more matching files was found;
sl@0
   526
        KErrNotFound if no matching file was found in the directory on any 
sl@0
   527
        of the drives.
sl@0
   528
        KErrArgument, if the filename is empty. 
sl@0
   529
                
sl@0
   530
@see TFindFile::FindWild
sl@0
   531
@see TFindFile::File
sl@0
   532
@see TFindFile::SetFindMask()
sl@0
   533
*/
sl@0
   534
	{
sl@0
   535
sl@0
   536
	iDir=&aDir;
sl@0
   537
	return(DoFindByDir(aFileName,aDirPath));
sl@0
   538
	}
sl@0
   539
sl@0
   540
sl@0
   541
sl@0
   542
sl@0
   543
TInt TFindFile::DoFind()
sl@0
   544
//
sl@0
   545
// Find the next match
sl@0
   546
//
sl@0
   547
	{
sl@0
   548
sl@0
   549
	TInt ret=KErrNone;
sl@0
   550
	switch(iMode)
sl@0
   551
		{
sl@0
   552
	case EFindByDrives:
sl@0
   553
		ret=DoFindNextInDriveList();
sl@0
   554
		break;
sl@0
   555
	case EFindByPath:
sl@0
   556
	case EFindByDrivesInPath:
sl@0
   557
		ret=DoFindNextInPath();
sl@0
   558
		break;
sl@0
   559
	default:
sl@0
   560
		Panic(EFindFileIllegalMode);
sl@0
   561
		}
sl@0
   562
	return(ret);
sl@0
   563
	}
sl@0
   564
sl@0
   565
sl@0
   566
sl@0
   567
sl@0
   568
EXPORT_C TInt TFindFile::Find()
sl@0
   569
/**
sl@0
   570
Searches for the next file/directory.
sl@0
   571
sl@0
   572
This should be used after a successful call to FindByPath() or FindByDir(), 
sl@0
   573
to find the next occurrence of the filename in the path or drive list.
sl@0
   574
sl@0
   575
Using function SetFindMask it is possible to specify a combination of 
sl@0
   576
attributes that the drives to be searched must match.
sl@0
   577
sl@0
   578
Note:
sl@0
   579
sl@0
   580
1. After a file/directory has been found, use TFindFile::File() to get the
sl@0
   581
   fully qualified path and filename.
sl@0
   582
sl@0
   583
@return KErrNone, if another occurrence of the file was found;
sl@0
   584
        KErrNotFound, if no more occurrences were found.
sl@0
   585
        
sl@0
   586
@see TFindFile::FindByPath
sl@0
   587
@see TFindFile::FindByDir
sl@0
   588
@see TFindFile::File
sl@0
   589
@see TFindFile::SetFindMask()
sl@0
   590
sl@0
   591
*/
sl@0
   592
	{
sl@0
   593
sl@0
   594
//	iDir=NULL;
sl@0
   595
	return(DoFind());
sl@0
   596
	}
sl@0
   597
sl@0
   598
sl@0
   599
sl@0
   600
sl@0
   601
EXPORT_C TInt TFindFile::FindWild(CDir*& aDir)
sl@0
   602
/**
sl@0
   603
Searches for the next file/directory.
sl@0
   604
sl@0
   605
This should be used after a successful call to FindWildByPath()
sl@0
   606
or FindWildByDir(), for the next occurrences of the filename in the
sl@0
   607
path or drive list.Using function SetFindMask it is possible to specify a 
sl@0
   608
combination of attributes that the drives to be searched must match.
sl@0
   609
sl@0
   610
Notes:
sl@0
   611
sl@0
   612
1. The caller of this function is responsible for deleting aDir after
sl@0
   613
   the function has returned 
sl@0
   614
sl@0
   615
2. Calling TFindFile::File() after a successful search, will return
sl@0
   616
   the drive letter and the directory containing the file(s).
sl@0
   617
   The filenames may be retrieved via the array of TEntry::iName objects
sl@0
   618
   contained in aDir. If you want to retrieve the fully qualified
sl@0
   619
   path of a file, you will need to parse the path and the filename using
sl@0
   620
   the TParse class or derived classes.
sl@0
   621
sl@0
   622
@param aDir On return, contains the entries for all matching files found in
sl@0
   623
            the next directory.
sl@0
   624
            
sl@0
   625
@return KErrNone, if further occurrences were found;
sl@0
   626
        KErrNotFound, if no more matching files were found.
sl@0
   627
sl@0
   628
sl@0
   629
@see TParse
sl@0
   630
@see TEntry::iName
sl@0
   631
@see TFindFile::File
sl@0
   632
@see TFindFile::FindWildByPath
sl@0
   633
@see TFindFile::FindWildByDir
sl@0
   634
@see TFindFile::SetFindMask()
sl@0
   635
*/
sl@0
   636
	{
sl@0
   637
sl@0
   638
	iDir=&aDir;
sl@0
   639
	return(DoFind());
sl@0
   640
	}
sl@0
   641
sl@0
   642
sl@0
   643
sl@0
   644
EXPORT_C TInt TFindFile::SetFindMask(TUint aMask)
sl@0
   645
/**
sl@0
   646
Can be used in order to specify a combination of drive attributes that the drives 
sl@0
   647
to be searched must match. When searching without specifying a mask, all drives, except the 
sl@0
   648
remote ones will be returned.
sl@0
   649
sl@0
   650
@param aMask The combination of drive attributes that we want the drives to match. 
sl@0
   651
sl@0
   652
@return KErrNone, if the mask supplied is correct.
sl@0
   653
        KErrArgument, if the mask supplied is invalid.
sl@0
   654
*/
sl@0
   655
sl@0
   656
	 {	
sl@0
   657
	 TInt r =ValidateMatchMask(aMask);
sl@0
   658
	 if(r!=KErrNone) 
sl@0
   659
	 	return r;
sl@0
   660
	 else
sl@0
   661
	 	{
sl@0
   662
	 	if(aMask != 0)
sl@0
   663
			iMatchMask = aMask;
sl@0
   664
		else 		
sl@0
   665
			iMatchMask  = (KDriveAttExclude |KDriveAttMatchedFlags) ; //KDriveAttMatchedFlags ==0xFF so this exclude all drives in DoFindNextInDriveList
sl@0
   666
	 	
sl@0
   667
	 	return KErrNone;
sl@0
   668
	 	
sl@0
   669
	 	}
sl@0
   670
	 
sl@0
   671
	
sl@0
   672
											
sl@0
   673
	 }
sl@0
   674