include
#include
#include
using namespace std;
#define IS_DAD_PATH(FileData) (!_tcscmp(FileData.cFileName,_T("."))) ||\
(!_tcscmp(FileData.cFileName,_T("..")))
#define IS_SON_PATH(FileData) (FileData.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)&&\
(_tcscmp(FileData.cFileName,_T(".")))&&(_tcscmp(FileData.cFileName,_T("..")))
#ifdef _UNICODE
#define Tstring std::wstring
#else
#define Tstring std::string
#endif
void FileSearch(wstring findRootPath)
{
wstring rootPath = findRootPath;
WIN32_FIND_DATA FindFileData;
WIN32_FIND_DATA FileNextData;
HANDLE hFind;
bool Ret = true;
wstring NodePath = findRootPath;
hFind = FindFirstFile(rootPath.c_str(), &FindFileData);
while ((hFind != INVALID_HANDLE_VALUE)&&(Ret))
{
if (IS_SON_PATH(FindFileData))
{
//如果是遍历文件夹的话,去子节点接着search
NodePath += _T("\\");
NodePath += FindFileData.cFileName;
FileSearch(NodePath);
}
else if (IS_DAD_PATH(FindFileData))
{
//TO DO ,你想干点啥,你能干点啥
}
else
{
//TO DO ,if not path,this is your file,and you can do you want to do
// please hulue zhege dantyengde yingyu
}
Ret = FindNextFile(hFind, &FindFileData);
}
if (hFind) FindClose(hFind);//释放句柄资源
}
win编程---遍历文件
最新推荐文章于 2021-01-08 09:52:42 发布