1 //
2 // EnumDirs.cpp
3 //
4 
5 #include "EnumDirs.h"
6 #include <stdio.h>
7 
8 #if defined(UNDER_CE) && !defined(assert)
9 #define assert(x)
10 #endif
11 
12 BOOL EnumDirs ( const TCHAR* szDirectory_, const TCHAR* szFileSpec, MYENUMDIRSPROC pProc, long lParam )
13 {
14 	assert ( szDirectory_ && szFileSpec && pProc );
15 	TCHAR szDirectory[MAX_PATH+1];
16 	TCHAR szSearchPath[MAX_PATH+1];
17 	TCHAR szTemp[MAX_PATH+1];
18 	_tcscpy ( szDirectory, szDirectory_ );
19 	if ( szDirectory[_tcslen(szDirectory)-1] != '\\' )
20 		_tcscat ( szDirectory, _T("\\") );
21 	_sntprintf ( szSearchPath, _MAX_PATH, _T("%s%s"), szDirectory, szFileSpec );
22 	WIN32_FIND_DATA wfd;
23 	HANDLE hfind = FindFirstFile ( szSearchPath, &wfd );
24 	if ( hfind == INVALID_HANDLE_VALUE )
25 		return TRUE;
26 	do
27 	{
28 		if ( !_tcscmp ( wfd.cFileName, _T(".") ) || !_tcscmp ( wfd.cFileName, _T("..") ) )
29 			continue;
30 		_sntprintf ( szTemp, _MAX_PATH, _T("%s%s"), szDirectory, wfd.cFileName );
31 		if ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
32 		{
33 			if ( !pProc ( &wfd, lParam ) )
34 			{
35 				FindClose ( hfind );
36 				return FALSE;
37 			}
38 		}
39 	} while ( FindNextFile ( hfind, &wfd ) );
40 	FindClose ( hfind );
41 	return TRUE;
42 }
43