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