• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 186
  • Last Modified:

Getting a directory listing

Is there an MFC way to get a list of files and subdirectories from a directory? If not, is there any good way? It doesn't need to be cross-platform compliant (though this is quite obvious after mentioning that I'm using MFC :P ).
0
SonicX_BlueBlur
Asked:
SonicX_BlueBlur
1 Solution
 
AxterCommented:
Hi SonicX_BlueBlur,
You can use Windows API FindFirstFile function

David Maisonave :-)
Cheers!
0
 
AxterCommented:
Here's an example:

WIN32_FIND_DATA fd;
     HANDLE hFind = ::FindFirstFile (_T ("*.exe"), &fd);
     if (hFind != INVALID_HANDLE_VALUE)
     {
          do
          {
               TRACE(fd.cFileName);
                                       // Do some thing  
          } while (::FindNextFile (hFind, &fd));
          ::FindClose (hFind);
     }
0
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.

 
SonicX_BlueBlurAuthor Commented:
Using the code that starts with the WIN32_FIND_DATA declaration, is it possible to determine if an entry is a directory or a file?
0
 
rcarlanCommented:
If you're using MFC, you may want to also look at CFileFind:

CFileFind oFileFind;
BOOL bContinue = oFileFind.FindFile(_T("*.txt"));
while (bContinue)
{
    bContinue = oFileFind.FindNextFile();
    if (oFileFind.IsDirectory())
    {
        // do something with the directory
    }
    else
    {
        // do something with the file
    }
}

Radu
0
 
nonubikCommented:
>Using the code that starts with the WIN32_FIND_DATA declaration, is it possible to determine if an entry is a directory or a file?

WIN32_FIND_DATA FindData;

.....

if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
  //we have a directory
}
0
 
SonicX_BlueBlurAuthor Commented:
I think rcarlan's way would be more of what I'm looking for. I assume I can also search for *.*?
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now