]>
git.saurik.com Git - wxWidgets.git/blob - src/common/dircmn.cpp
c39290a58cdc418f6845ad6478cd424ac44233fd
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/dircmn.cpp
3 // Purpose: wxDir methods common to all implementations
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // License: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 /* this is done in platform-specific files
22 #pragma implementation "dir.h"
26 // For compilers that support precompilation, includes "wx.h".
27 #include "wx/wxprec.h"
34 #include "wx/string.h"
41 // ============================================================================
43 // ============================================================================
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 size_t wxDir::Traverse(wxDirTraverser
& sink
,
50 const wxString
& filespec
,
53 wxCHECK_MSG( IsOpened(), (size_t)-1,
54 _T("dir must be opened before traversing it") );
56 // the total number of files found
59 // the name of this dir with path delimiter at the end
60 wxString prefix
= GetName();
61 prefix
+= wxFILE_SEP_PATH
;
63 // first, recurse into subdirs
64 if ( flags
& wxDIR_DIRS
)
67 bool cont
= GetFirst(&dirname
, _T(""), wxDIR_DIRS
| wxDIR_HIDDEN
);
70 wxDirTraverseResult res
= sink
.OnDir(prefix
+ dirname
);
72 if ( res
== wxDIR_STOP
)
75 if ( res
== wxDIR_CONTINUE
)
77 wxDir
subdir(prefix
+ dirname
);
78 if ( subdir
.IsOpened() )
80 nFiles
+= subdir
.Traverse(sink
, filespec
, flags
);
85 wxASSERT_MSG( res
== wxDIR_IGNORE
,
86 _T("unexpected OnDir() return value") );
89 cont
= GetNext(&dirname
);
93 // now enum our own files
94 if ( flags
& wxDIR_FILES
)
99 bool cont
= GetFirst(&filename
, filespec
, flags
);
102 wxDirTraverseResult res
= sink
.OnFile(prefix
+ filename
);
103 if ( res
== wxDIR_STOP
)
106 wxASSERT_MSG( res
== wxDIR_CONTINUE
,
107 _T("unexpected OnFile() return value") );
111 cont
= GetNext(&filename
);
118 // ----------------------------------------------------------------------------
119 // wxDir::GetAllFiles()
120 // ----------------------------------------------------------------------------
122 class wxDirTraverserSimple
: public wxDirTraverser
125 wxDirTraverserSimple(wxArrayString
& files
) : m_files(files
) { }
127 virtual wxDirTraverseResult
OnFile(const wxString
& filename
)
129 m_files
.Add(filename
);
130 return wxDIR_CONTINUE
;
133 virtual wxDirTraverseResult
OnDir(const wxString
& WXUNUSED(dirname
))
135 return wxDIR_CONTINUE
;
139 wxArrayString
& m_files
;
143 size_t wxDir::GetAllFiles(const wxString
& dirname
,
144 wxArrayString
*files
,
145 const wxString
& filespec
,
148 wxCHECK_MSG( files
, (size_t)-1, _T("NULL pointer in wxDir::GetAllFiles") );
153 if ( dir
.IsOpened() )
155 wxDirTraverserSimple
traverser(*files
);
157 nFiles
+= dir
.Traverse(traverser
, filespec
, flags
);