+4  A: 

CFileFind::IsDirectory()

http://msdn.microsoft.com/en-us/library/scx99850(VS.80).aspx

EDIT:

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

  using namespace std;

  CFileFind finder;

  fileName += _T("c:\\aDirName");
  if (finder.FindFile(fileName))
  {
        if (finder.FindNextFIle())
        {            
              if (finder.IsDirectory())
              {
                    // Do directory stuff...
              }
        }
  }

If you change filename to have wildcards, you can do a

  while(finder.findNextFile()) {...

to get all matching files.

Byron Whitlock
Can you please post a snippet with it's usage? The code posted by microsoft isn't helping me with what I'm trying to achieve.
Geo
Please tell me , why are you sending a .txt file as it's argument and then checking for other files ? Correct me if I'm wrong , but if I don't send a wildcard to the object , why will it continue to search for files ?
Geo
FindFileName() doesn't actually find the first file. It just returns an error if the file glob isn't found. FindNextFile() will grab the file/directory. Look at the MS code, see that findNextFile() is called before operating on the file itself. This is a very common pattern in MFC.
Byron Whitlock
I removed the extraneous checking for current/parent directory (isDots), perhaps that was confusing?
Byron Whitlock
+1  A: 

Sorry for possibly "inconsistency" of answer to question but may be you'll see it useful because anytime I need something like this in Windows I am NOT using MFC but regular Windows API:

//not completely tested but after some debug I'm sure it'll work
bool IsDirectory(LPCTSTR sDirName)
{
    //First define special structure defined in windows
    WIN32_FIND_DATA findFileData; ZeroMemory(&findFileData, sizeof(WIN32_FIND_DATA));
    //after that call WinAPI function finding file\directory
    //(don't forget to close handle after all!)
    HANDLE hf = ::FindFirstFile(sDirName, &findFileData);
    if (hf  ==  INVALID_HANDLE_VALUE) //also predefined value - 0xFFFFFFFF
    return false;
    //closing handle!
    ::FindClose(hf);
    // true if directory flag in on
    return (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;
}
bgee
I like your answer ! Thanks !
Geo
+1  A: 

MFC solution as requested: a_FSItem path ot the item to test (examine the CFile::GetStatus() for the needed requirements).

  CFileStatus t_aFSItemStat;
  CFile::GetStatus( a_FSItem, t_aFSItemStat );

  if ( ( t_aFSItemStat.m_attribute & CFile::directory )
    return true;

  return false;

if you wish to include a volume root as a valid directory just add it to the test

t_aFSItemStat.m_attribute & CFile::volume
Panic
+1  A: 

Its not MFC, but I use this:

bool IsValidFolder(LPCTSTR pszPath)
{
    const DWORD dwAttr = ::GetFileAttributes(pszPath);
    if(dwAttr != 0xFFFFFFFF)
    {
        if((FILE_ATTRIBUTE_DIRECTORY & dwAttr) &&
           0 != _tcscmp(_T("."), pszPath) &&
           0 != _tcscmp(_T(".."), pszPath))
        {
            return true;
        }
    }

    return false;
}
BrianK