mfc >> Using CFileFind::FindNextFile() in a Loop

by U1NSb3k » Fri, 17 Mar 2006 18:27:06 GMT

I have some doubt using CFileFind::FindNextFile() function. How can I use
this function in a loop to check all files matching a particular criteria.
When it gets the 'last' matching file what it returns? Also when it gets 'no
more' matching files - what does it return?

Please help with code example -- as MSDN doesn't say much clear about these
things

Sincerely
Sanjoy Sinha Roy
HCL Technologies



mfc >> Using CFileFind::FindNextFile() in a Loop

by Mathieu DEGROUX » Fri, 17 Mar 2006 19:59:29 GMT


SSRoy a crit :

here is a sample

void Recurse(LPCTSTR pstr)
{
CFileFind finder;

// build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("\\*.*");

// start working for files
BOOL bWorking = finder.FindFile(strWildcard);

while (bWorking)
{
bWorking = finder.FindNextFile();

// skip . and .. files; otherwise, we'd
// recur infinitely!

if (finder.IsDots())
continue;

// if it's a directory, recursively search it

if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
cout << (LPCTSTR) str << endl;
Recurse(str);
}
}

finder.Close();
}



mfc >> Using CFileFind::FindNextFile() in a Loop

by Tom Serface » Sat, 18 Mar 2006 00:55:11 GMT

I wrote an extended version of this class that might be a good example to
you, or have something you could use.

Tom

http://www.codeproject.com/file/CFileFindEx.asp








Similar Threads

1. Problem using CFileFind on SMB server on LAN

2. Using CFileFind over https?

I am trying to use CFileFind object to find a file located on a remote
server having a URL like "https://RemoteDirectory/FileName.extn".
This does not seem to work.
However, the same approach workd for a File located at my local
machine ( with the URL like "\\FolderName\FileName.extn").
Can the CFileFind class be used to search for files stored on https://
-like locations?
If so, some sample code would help.
If not, which class/API in MFC can be used for this task?





3. Using for loop iterator after the loop

4. FindFirstFile and FindNextFile

Hi, all!

We are devleping one app that will use disk access with FindFirstFile and 
FindNextFile for it. Can someone expose me how works FindFirstFile and 
FindNextFile  in disk access? Does the findFirstfile read all files of disk 
and put in physical memory  , and FindFirstFile read files from memory? Can 
someone help us?

Thanks in advance.

5. NewbieQ: FindNextFile

6. FindFirstFile, FindNextFile to get files in the order of receipt

Hi,

I need to get the files in a directory in a list, in the same order as they 
were created in the directory.
The directory gets the files written onto it periodically from various 
programs and when I am peforming FindNext on this directory I want the files 
to be fetched in the same order in whihc they were copied/written to this 
directory.
Is there any flag or any option which can help me achieve this.

Thanks and Regards
Ganga 


7. CFtpFileFind::FindNextFile() can't get the correct file name.

8. FindFirstFile, how much faster than FindNextFile?

Which is faster, more efficient?

... a switch statement with 45 cases executing 1 FindFirstFile()
... using FindNextFile() to search for a substring in 50 filenames 
(files in the same folder)

The switch statement looks like this.

switch(wParam)
{
case 33:
   {
      FileHandle=FindFirstFile("C:\\*KeyA.txt",&FindData);
      strcpy(FileName,"KeyA.txt");
      break;
   }
   ... 44 additional similar cases
}

If that is not used, FindNextFile() will be used to search for a 
substring in each of about 50 filenames, something maybe similar to 
this.

HANDLE FileHandle=FindFirstFile("C:\\*.txt",&dirInfo);
if(FileHandle!=INVALID_HANDLE_VALUE)
{
   do
   {
       using strstr() to search 50 filenames for a given 
       substring like "KeyB"
   }
   while(::FindNextFile(FileHandle,&FindData));
}
::FindClose(FileHandle);

I will be happy to clarify if my question is not clear enough. If the 
answer is too difficult, please disregard.

Thank you.






-- 
United States and British intelligence agencies admittedly break the 
law while spying on each other. United States and British governments 
claim to energetically share that information.