📄 recursive_walk.h
字号:
#ifndef _RECURSIVE_WALK_H
#define _RECURSIVE_WALK_H
#define IS_DIR(fd) (((fd)->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
extern "C" void add_filename(LPTSTR s, LPCTSTR name)
{
int l = _tcsclen(s);
if( l )
if( s[l-1] != _T('\\') )
{
s[l] = _T('\\');
s[l+1] = 0;
}
_tcscat(s, name);
}
typedef BOOL (CALLBACK* PFN_ONFOUND)(const WIN32_FIND_DATA* fd, LPCTSTR fullpath, DWORD data);
extern "C" BOOL recursive_walk(LPCTSTR path, PFN_ONFOUND on_found, DWORD data = 0)
{
HANDLE h = NULL;
BOOL res = TRUE;
WIN32_FIND_DATA fd;
TCHAR full_path[MAX_PATH];
ZeroMemory(&fd, sizeof(fd));
_tcscpy(full_path, path);
add_filename(full_path, _T("*.*"));
h = FindFirstFile(full_path, &fd);
if( !h )
return TRUE;
for(;;)
{
if( fd.cFileName[0] != _T('.') )
{
_tcscpy(full_path, path);
add_filename(full_path, fd.cFileName);
DWORD r = GetFullPathName(full_path, MAX_PATH, full_path, NULL);
if( on_found )
{
if( !on_found(&fd, full_path, data) )
{
res = FALSE;
break;
}
}
if( IS_DIR(&fd) )
{
if( !recursive_walk(full_path, on_found, data) )
{
res = FALSE;
break;
}
}
else
{
}
}
if( !FindNextFile(h, &fd) )
break;
}
FindClose(h);
return res;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -