ReactOS 0.4.16-dev-338-g34e76ad
EnumFilesImpl.h File Reference
#include "EnumFiles.h"
#include "FixLFN.h"
#include "safestr.h"
#include <direct.h>
#include <stdio.h>
Include dependency graph for EnumFilesImpl.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BOOL EnumFilesInDirectory (const TCHAR *szDirectory_, const TCHAR *szFileSpec, MYENUMFILESPROC pProc, long lParam, BOOL bSubsToo, BOOL bSubsMustMatchFileSpec)
 

Function Documentation

◆ EnumFilesInDirectory()

BOOL EnumFilesInDirectory ( const TCHAR szDirectory_,
const TCHAR szFileSpec,
MYENUMFILESPROC  pProc,
long  lParam,
BOOL  bSubsToo,
BOOL  bSubsMustMatchFileSpec 
)

Definition at line 13 of file EnumFilesImpl.h.

14{
15 TCHAR szDirectory[MAX_PATH+1];
16 TCHAR szSearchPath[MAX_PATH+1];
17 TCHAR szTemp[MAX_PATH+1];
18
19 if ( safestrlen(szDirectory_) > MAX_PATH || !szFileSpec || !pProc )
20 return FALSE;
21 if ( szDirectory_ )
22 _tcscpy ( szDirectory, szDirectory_ );
23 else
24#ifdef UNDER_CE
25 _tcscpy ( szDirectory, _T("") );
26#else//UNDER_CE
27 getcwd ( szDirectory, sizeof(szDirectory)-1 );
28#endif//UNDER_CE
29 int dirlen = _tcslen(szDirectory);
30 if ( dirlen > 0 && szDirectory[dirlen-1] != '\\' )
31 _tcscat ( szDirectory, _T("\\") );
32
33 // first search for all files in directory that match szFileSpec...
34 _sntprintf ( szSearchPath, sizeof(szSearchPath)-1, _T("%s%s"), szDirectory, szFileSpec );
36 HANDLE hfind = FindFirstFile ( szSearchPath, &wfd );
37 if ( hfind != INVALID_HANDLE_VALUE )
38 {
39 do
40 {
41 if ( !_tcscmp ( wfd.cFileName, _T(".") ) || !_tcscmp ( wfd.cFileName, _T("..") ) )
42 continue;
43 if ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
44 {
45 if ( !bSubsMustMatchFileSpec )
46 continue;
47 _sntprintf ( szTemp, sizeof(szTemp)-1, _T("%s%s"), szDirectory, wfd.cFileName );
48 if ( bSubsToo )
49 {
50 if ( !EnumFilesInDirectory ( szTemp, szFileSpec, pProc, lParam, bSubsToo, bSubsMustMatchFileSpec ) )
51 {
52 FindClose ( hfind );
53 return FALSE;
54 }
55 }
56 }
57 _sntprintf ( szTemp, sizeof(szTemp)-1, _T("%s%s"), szDirectory, wfd.cFileName );
58 FixLFN(szTemp,szTemp);
59 if ( !pProc ( &wfd, szTemp, lParam ) )
60 {
61 FindClose ( hfind );
62 return FALSE;
63 }
64 } while ( FindNextFile ( hfind, &wfd ) );
65 FindClose ( hfind );
66 }
67 if ( !bSubsToo || bSubsMustMatchFileSpec )
68 return TRUE;
69
70 // now search for all subdirectories...
71 _sntprintf ( szSearchPath, sizeof(szSearchPath)-1, _T("%s*.*"), szDirectory );
72 hfind = FindFirstFile ( szSearchPath, &wfd );
73 if ( hfind != INVALID_HANDLE_VALUE )
74 {
75 do
76 {
77 if ( !_tcscmp ( wfd.cFileName, _T(".") ) || !_tcscmp ( wfd.cFileName, _T("..") ) )
78 continue;
79 if ( !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) )
80 continue;
81 _sntprintf ( szTemp, sizeof(szTemp)-1, _T("%s%s"), szDirectory, wfd.cFileName );
82 if ( FALSE == EnumFilesInDirectory ( szTemp, szFileSpec, pProc, lParam, bSubsToo, bSubsMustMatchFileSpec ) )
83 {
84 FindClose ( hfind );
85 return FALSE;
86 }
87 } while ( FindNextFile ( hfind, &wfd ) );
88 FindClose ( hfind );
89 }
90
91 return TRUE;
92}
BOOL EnumFilesInDirectory(const TCHAR *szDirectory_, const TCHAR *szFileSpec, MYENUMFILESPROC pProc, long lParam, BOOL bSubsToo, BOOL bSubsMustMatchFileSpec)
Definition: EnumFilesImpl.h:13
int FixLFN(const TCHAR *pBadFileName, TCHAR *pGoodFileName)
Definition: FixLFN.h:12
LPARAM lParam
Definition: combotst.c:139
_Check_return_ _Ret_opt_z_ _CRTIMP char *__cdecl getcwd(_Out_writes_opt_(_SizeInBytes) char *_DstBuf, _In_ int _SizeInBytes)
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
#define _tcscmp
Definition: tchar.h:1424
#define _tcscat
Definition: tchar.h:622
#define _tcscpy
Definition: tchar.h:623
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
size_t safestrlen(const tchar *string)
Definition: safestr.h:19
#define _T(x)
Definition: vfdio.h:22
#define FindNextFile
Definition: winbase.h:3813
#define FindFirstFile
Definition: winbase.h:3807
char TCHAR
Definition: xmlstorage.h:189
#define _sntprintf
Definition: xmlstorage.h:201
#define _tcslen
Definition: xmlstorage.h:198

Referenced by EnumFilesInDirectory().