Solved

CFindFile  - conditional FindFile() filter?

Posted on 2004-08-10
9
851 Views
Last Modified: 2012-05-05
Right now I have this which works:

CFileFind ff ;
BOOL bWorking = ff.(sDir + _T("\\") + _T("*.txt")) ;
while (bWorking)
{
  .. // etc..

It will get all .txt files, it works just fine.

I now have files which are called  "xxxx_port.txt" - I need to exclude these from the selection of *.txt

Is there a way to modify that line so to get:   *.txt || !(*_port.txt)  type of thing?

thanks
-Paul
0
Comment
Question by:PMH4514
  • 6
  • 2
9 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 11767099
>>Is there a way to modify that line so to get:   *.txt || !(*_port.txt)  type of thing?

No, but you can add an extra search just for the xxxx_port.txt files, and compare the results to your original search.
0
 
LVL 86

Accepted Solution

by:
jkr earned 30 total points
ID: 11767129
Try http://www.codeproject.com/file/fileglob.asp ("Recursive patterned File Globbing")
0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 20 total points
ID: 11767179
Check out the code in the following link:

http://code.axter.com/FindFilesInPath.h
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:PMH4514
ID: 11767214
thank you both.
-Paul
0
 
LVL 30

Expert Comment

by:Axter
ID: 11767296
Example code usuage of above link:

void Test(const CString &sDir)
{
      FindFilesInPath ff(sDir + _T("\\"), _T("*.txt"));
      FindFilesInPath ff_Unwanted(sDir + _T("\\"), _T("????_port.txt"));
      for (int i = 0;i < ff.c_FileList.GetSize();++i)
      {
            BOOL IsUnwanted = FALSE;
            for (int b = 0;b < ff_Unwanted.c_FileList.GetSize();++b)
            {
                  if (ff.c_FileList[i] == ff_Unwanted.c_FileList[b] )
                  {
                        IsUnwanted = TRUE;
                        break;
                  }
            }
            if (IsUnwanted) continue;
            //Process good file here
            AfxMessageBox(ff.c_FileList[i]);
      }
}

0
 
LVL 30

Expert Comment

by:Axter
ID: 11767358
FYI:
If you want to exclude all files that have a _port.txt ending, then modify above code to the following:
FindFilesInPath ff_Unwanted(sDir + _T("\\"), _T("*_port.txt"));

That will exclude files like the following:
1234_port.txt
abcd_port.txt
foo_port.txt
wiget123_port.txt


Where as ("????_port.txt") will only exculde files that have exactly four characters before _port.txt.
1234_port.txt
abcd_port.txt
0
 
LVL 30

Expert Comment

by:Axter
ID: 11767607
Last bit,
I just modified the code in http://code.axter.com/FindFilesInPath.h 
And I added a RemoveFromList function.

You can know use the following method:

void Test(const CString &sDir)
{
      FindFilesInPath WantedFileTypes(sDir + _T("\\"), _T("*.txt"));
      FindFilesInPath UnWantedFileTypes(sDir + _T("\\"), _T("????_port.txt"));
      WantedFileTypes.RemoveFromList(UnWantedFileTypes.c_FileList);
      for (int i = 0;i < WantedFileTypes.c_FileList.GetSize();++i)
      {
            //Process good file here
            AfxMessageBox(WantedFileTypes.c_FileList[i]);
      }
}

0
 
LVL 30

Expert Comment

by:Axter
ID: 11767638
OK, this is really the last post.

I forgot to add, that if you need the full path, use c_StartingPathList member function in conjunction with c_FileList.

Example:
AfxMessageBox(WantedFileTypes.c_StartingPathList[i] + WantedFileTypes.c_FileList[i]);
0
 

Author Comment

by:PMH4514
ID: 11768316
thanks Axter!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question