Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio
Visual C++
Reference
MFC
Classes
CFileFind Class
Member Functions
CFileFind::IsDirectory
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
MFC Library Reference
CFileFind::IsDirectory

Call this member function to determine if the found file is a directory.

BOOL IsDirectory( ) const;

Nonzero if successful; otherwise 0.

A file that is a directory is marked with FILE_ATTRIBUTE_DIRECTORY a file attribute identified in the WIN32_FIND_DATA structure.

You must call FindNextFile at least once before calling IsDirectory.

See the member function MatchesMask for a complete list of file attributes.

This small program recurses every directory on the C:\ drive and prints the name of the directory.

#include <afxwin.h>
#include <iostream>

using namespace std;

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();
}

int main()
{
   if (!AfxWinInit(GetModuleHandle(NULL), NULL, GetCommandLine(), 0))
      cout << "panic!" << endl;
   else
      Recurse(_T("C:"));
}
Tags What's this?: Add a tag
Community Content What is Community Content?
Add new contentRSS Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker