?
Solved

CFindFile  - conditional FindFile() filter?

Posted on 2004-08-10
9
Medium Priority
?
862 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 120 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 80 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

777 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