Wildcard search  
Author Message
1320Life





PostPosted: Sat Aug 26 05:18:23 CDT 2006 Top

MFC >> Wildcard search

How to do wild card search for filename
like c:\doc??ents\abc???\*.exe this????

Findfile will not work for this.Is there any other way to do it or any work
arround??

Visual Studio22  
 
 
Heinz





PostPosted: Sat Aug 26 05:18:23 CDT 2006 Top

MFC >> Wildcard search

> How to do wild card search for filename
> like c:\doc??ents\abc???\*.exe this????
>
> Findfile will not work for this.Is there any other way to do it or any
> work
> arround??

Wildcards are not allowed in a path. You must tell FileFind where to look
for files and folders. If you want to search for files in multiple folders,
where the folder names may contain wildcards themselves, you have to write
your own function to do this. You could start with a function

void MyFindFile(std::list<CString>& foundFiles, CString root, CString
pattern);

and call it as

std::List<CString> files;
MyFileFind(files, _T("c:\\"), _T("doc??ents\\abc???\\*.exe"));

MyFileFind could be implemented basically like this:

1. Look for the first wildcard in pattern and remember its position:
int wcPos = pattern.FindOneOf(_T("?*"));

2. Look for the first \ following the wildcard found in step 1
int bsPos = pattern.Find(_T('\\'), wcPos);

3. If no backslash has been found in step 1 use CFileFind to search for all
files matching root+pattern. Append those files to the list of al found
files and return.

4. Use CFileFind to search for all folders matching
root+pattern.Left(byPos). For each directory found call
MyFileFind(list, finder.GetFilePath()+_T('\\'), pattern.Mid(bsPos+1));
where "finder" is the name of your CFileFind object used in this step.

HTH
Heinz

 
 
Tom





PostPosted: Mon Aug 28 11:18:59 CDT 2006 Top

MFC >> Wildcard search
sbcglobal.net and I'll send you the latest version if you'd like (it's not
much different just better Unicode support).

http://www.codeproject.com/file/CFileFindEx.asp

Tom



> How to do wild card search for filename
> like c:\doc??ents\abc???\*.exe this????
>
> Findfile will not work for this.Is there any other way to do it or any
> work
> arround??
>
>