]>
git.saurik.com Git - wxWidgets.git/blob - src/common/dircmn.cpp
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"
37 #include "wx/filefn.h"
42 // ============================================================================
44 // ============================================================================
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 size_t wxDir::Traverse(wxDirTraverser
& sink
,
51 const wxString
& filespec
,
54 wxCHECK_MSG( IsOpened(), (size_t)-1,
55 _T("dir must be opened before traversing it") );
57 // the total number of files found
60 // the name of this dir with path delimiter at the end
61 wxString prefix
= GetName();
62 prefix
+= wxFILE_SEP_PATH
;
64 // first, recurse into subdirs
65 if ( flags
& wxDIR_DIRS
)
68 bool cont
= GetFirst(&dirname
, _T(""), wxDIR_DIRS
| wxDIR_HIDDEN
);
71 wxDirTraverseResult res
= sink
.OnDir(prefix
+ dirname
);
73 if ( res
== wxDIR_STOP
)
76 if ( res
== wxDIR_CONTINUE
)
78 wxDir
subdir(prefix
+ dirname
);
79 if ( subdir
.IsOpened() )
81 nFiles
+= subdir
.Traverse(sink
, filespec
, flags
);
86 wxASSERT_MSG( res
== wxDIR_IGNORE
,
87 _T("unexpected OnDir() return value") );
90 cont
= GetNext(&dirname
);
94 // now enum our own files
95 if ( flags
& wxDIR_FILES
)
100 bool cont
= GetFirst(&filename
, filespec
, flags
);
103 wxDirTraverseResult res
= sink
.OnFile(prefix
+ filename
);
104 if ( res
== wxDIR_STOP
)
107 wxASSERT_MSG( res
== wxDIR_CONTINUE
,
108 _T("unexpected OnFile() return value") );
112 cont
= GetNext(&filename
);
119 // ----------------------------------------------------------------------------
120 // wxDir::GetAllFiles()
121 // ----------------------------------------------------------------------------
123 class wxDirTraverserSimple
: public wxDirTraverser
126 wxDirTraverserSimple(wxArrayString
& files
) : m_files(files
) { }
128 virtual wxDirTraverseResult
OnFile(const wxString
& filename
)
130 m_files
.Add(filename
);
131 return wxDIR_CONTINUE
;
134 virtual wxDirTraverseResult
OnDir(const wxString
& WXUNUSED(dirname
))
136 return wxDIR_CONTINUE
;
140 wxArrayString
& m_files
;
144 size_t wxDir::GetAllFiles(const wxString
& dirname
,
145 wxArrayString
*files
,
146 const wxString
& filespec
,
149 wxCHECK_MSG( files
, (size_t)-1, _T("NULL pointer in wxDir::GetAllFiles") );
154 if ( dir
.IsOpened() )
156 wxDirTraverserSimple
traverser(*files
);
158 nFiles
+= dir
.Traverse(traverser
, filespec
, flags
);