首页 > 代码库 > MFC 文件I/O和串行化

MFC 文件I/O和串行化

1.枚举所有文件夹(递归)

void EnumerateFolders (){    WIN32_FIND_DATA fd;    HANDLE hFind = ::FindFirstFile (_T ("*.*"), &fd);    if (hFind != INVALID_HANDLE_VALUE) {        do {            if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {                CString name = fd.cFileName;                if (name != _T (".") && name != _T ("..")) {                    TRACE (_T ("%s\n"), fd.cFileName);                    ::SetCurrentDirectory (fd.cFileName);                    EnumerateFolders ();                    ::SetCurrentDirectory (_T (".."));                }            }        } while (::FindNextFile (hFind, &fd));        ::FindClose (hFind);    }}
//比如说枚举E:\svn文件夹,不过可能会导致栈溢出
::SetCurrentDirectory(_T("e:\\svn"));
EnumerateFolders();