[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

CFindFile  - conditional FindFile() filter?

Posted on 2004-08-10
9
Medium Priority
?
867 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
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.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.
Suggested Courses

656 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