57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
#include "FileSystemUtil.h"
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include <windows.h>
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <string>
|
|
#include <functional>
|
|
void _FindFileRev(const std::string& dirname,
|
|
const int skiplevel,const int maxlevel,int nowlevel,
|
|
const std::function<void(const std::string&)>& func)
|
|
{
|
|
std::string patternString=dirname+"*";
|
|
|
|
WIN32_FIND_DATA fnd;
|
|
HANDLE hand=FindFirstFile(patternString.c_str(),&fnd);
|
|
if(hand!=INVALID_HANDLE_VALUE)
|
|
{
|
|
do
|
|
{
|
|
std::string fullname=dirname+fnd.cFileName;
|
|
if(fnd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
{
|
|
if(maxlevel>0 && nowlevel<maxlevel)
|
|
{
|
|
fullname.append("\\");
|
|
_FindFileRev(fullname,skiplevel,maxlevel,nowlevel+1,func);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if(nowlevel>skiplevel) func(fullname);
|
|
}
|
|
}
|
|
while(FindNextFile(hand,&fnd));
|
|
FindClose(hand);
|
|
}
|
|
}
|
|
void FindFileRev(const std::string& dirname,
|
|
const int skiplevel,const int maxlevel,
|
|
const std::function<void(const std::string&)>& func)
|
|
{
|
|
if(dirname[dirname.size()-1]!='\\')
|
|
{
|
|
std::string dirnamex=dirname+"\\";
|
|
_FindFileRev(dirnamex,skiplevel,maxlevel,1,func);
|
|
}
|
|
else
|
|
{
|
|
_FindFileRev(dirname,skiplevel,maxlevel,1,func);
|
|
}
|
|
}
|
|
|
|
#endif // _WIN32
|