诗词
字典
板报
句子
名言
励志
学校
友答
搜索
首页
中考频道
作文频道
公务员频道
出国留学
医药考试
司法考试
图书频道
外语考试
建筑工程
成人高考
故事频道
教程频道
文档频道
早教
星座频道
校园
求职招聘
考研频道
职业资格
自考频道
计算机考试
财会考试
高考频道
当前位置:
首页
>
教程频道
>
操作系统
>
windows
>
Windows上遍历文件目录
2012-07-08
Windows下遍历文件目录最近用到遍历文件目录,总结一下:void BuildRegSystem(const tstring& strFileSystem
Windows下遍历文件目录
最近用到遍历文件目录,总结一下:
void BuildRegSystem( const tstring& strFileSystemPath, const tstring& strAddParPath, CSysMgr& mgr ){ tstring strFsPath = strFileSystemPath; tstring strEnumPath = strFileSystemPath; tstring strAddNewPath = strAddParPath; if (*strFsPath.rbegin() != _T('\\')) { strFsPath += _T('\\'); } if (*strAddNewPath.rbegin() != _T('\\')) { strAddNewPath += _T('\\'); } strEnumPath = strFsPath + _T("*.*"); WIN32_FIND_DATA fndFile; HANDLE hFnd = ::FindFirstFile(strEnumPath.c_str(), &fndFile); if (hFnd == INVALID_HANDLE_VALUE) { return ; } while (::FindNextFile(hFnd, &fndFile)) { tstring strFileName = fndFile.cFileName; if (strFileName == _T("..")) {// 如果是上级目录,则不管. continue; } if (fndFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { // 如果是文件夹,则进行递归. mgr.CreateRegDirectory(strAddNewPath + strFileName); BuildRegSystem( strFsPath + strFileName, strAddNewPath + strFileName, regSystem ); } else { mgr.InsertEntry(strAddParPath, strFileName); } } ::FindClose(hFnd);}void Test(){ CSysMgr mgr; BuildRegSystem(_T("D:\\Program Files\\11game"), _T("\\"), mgr); // ... // ...}
没有任何复杂的操作,只为备忘。