Solved

CFindFile  - conditional FindFile() filter?

Posted on 2004-08-10
9
838 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
Comment Utility
>>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
Comment Utility
Try http://www.codeproject.com/file/fileglob.asp ("Recursive patterned File Globbing")
0
 
LVL 30

Assisted Solution

by:Axter
Axter earned 20 total points
Comment Utility
Check out the code in the following link:

http://code.axter.com/FindFilesInPath.h
0
 

Author Comment

by:PMH4514
Comment Utility
thank you both.
-Paul
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 30

Expert Comment

by:Axter
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
thanks Axter!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
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.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now