Solved

CFindFile  - conditional FindFile() filter?

Posted on 2004-08-10
9
846 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Better understanding on C++ Class serialization and formats 9 78
Header of docx file 17 113
Precision Problem in C++ 7 43
Adding items to a C# list incrementally 5 29
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…
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 goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

808 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