]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/dir.tex
documented wxInitialize and wxUnitialize
[wxWidgets.git] / docs / latex / wx / dir.tex
CommitLineData
35332784
VZ
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: dir.tex
3%% Purpose: wxDir documentation
4%% Author: Vadim Zeitlin
5%% Modified by:
6%% Created: 04.04.00
7%% RCS-ID: $Id$
8%% Copyright: (c) Vadim Zeitlin
9%% License: wxWindows license
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4afd7529
VZ
11
12\section{\class{wxDir}}\label{wxdir}
13
14wxDir is a portable equivalent of Unix {open/read/close}dir functions which
15allow enumerating of the files in a directory. wxDir allows enumerate files as
16well as directories.
17
35332784
VZ
18wxDir also provides a flexible way to enumerate files recursively using
19\helpref{Traverse}{wxdirtraverse} or a simpler
20\helpref{GetAllFiles}{wxdirgetallfiles} function.
21
4afd7529
VZ
22Example of use:
23
24\begin{verbatim}
25 wxDir dir(wxGetCwd());
26
27 if ( !dir.IsOpened() )
28 {
29 // deal with the error here - wxDir would already log an error message
30 // explaining the exact reason of the failure
31 return;
32 }
33
34 puts("Enumerating object files in current directory:");
35
36 wxString filename;
37
38 bool cont = dir.GetFirst(&filename, filespec, flags);
39 while ( cont )
40 {
41 printf("%s\n", filename.c_str());
42
43 cont = dir.GetNext(&filename);
44 }
45\end{verbatim}
46
47\wxheading{Derived from}
48
49No base class
50
51\wxheading{Constants}
52
53These flags define what kind of filenames is included in the list of files
54enumerated by GetFirst/GetNext
55
56{\small
57\begin{verbatim}
58enum
59{
60 wxDIR_FILES = 0x0001, // include files
61 wxDIR_DIRS = 0x0002, // include directories
62 wxDIR_HIDDEN = 0x0004, // include hidden files
63 wxDIR_DOTDOT = 0x0008, // include '.' and '..'
64
65 // by default, enumerate everything except '.' and '..'
85ec2f26 66 wxDIR_DEFAULT = wxDIR_FILES | wxDIR_DIRS | wxDIR_HIDDEN
4afd7529
VZ
67}
68\end{verbatim}
69}
70
71\wxheading{Include files}
72
73<wx/dir.h>
74
75\latexignore{\rtfignore{\wxheading{Members}}}
76
77\membersection{wxDir::Exists}\label{wxdirexists}
78
79\func{static bool}{Exists}{\param{const wxString\& }{dir}}
80
81Test for existence of a directory with the given name
82
83\membersection{wxDir::wxDir}\label{wxdirwxdir}
84
85\func{}{wxDir}{\void}
86
87Default constructor, use \helpref{Open()}{wxdiropen} afterwards.
88
89\func{}{wxDir}{\param{const wxString\& }{dir}}
90
91Opens the directory for enumeration, use \helpref{IsOpened()}{wxdirisopened}
92to test for errors.
93
94\membersection{wxDir::\destruct{wxDir}}\label{wxdirdtor}
95
96\func{}{\destruct{wxDir}}{\void}
97
98Destructor cleans up the associated ressources. It is not virtual and so this
99class is not meant to be used polymorphically.
100
101\membersection{wxDir::Open}\label{wxdiropen}
102
103\func{bool}{Open}{\param{const wxString\& }{dir}}
104
105Open the directory for enumerating, returns TRUE on success or FALSE if an
f6bcfd97 106error occurred.
4afd7529
VZ
107
108\membersection{wxDir::IsOpened}\label{wxdirisopened}
109
110\constfunc{bool}{IsOpened}{\void}
111
112Returns TRUE if the directory was successfully opened by a previous call to
113\helpref{Open}{wxdiropen}.
114
115\membersection{wxDir::GetFirst}\label{wxdirgetfirst}
116
117\constfunc{bool}{GetFirst}{\param{wxString* }{filename}, \param{const wxString\& }{filespec = wxEmptyString}, \param{int }{flags = wxDIR\_DEFAULT}}
118
119Start enumerating all files matching {\it filespec} (or all files if it is
120empty) and flags, return TRUE on success.
121
122\membersection{wxDir::GetNext}\label{wxdirgetnext}
123
124\constfunc{bool}{GetNext}{\param{wxString* }{filename}}
125
126Continue enumerating files satisfying the criteria specified by the last call
127to \helpref{GetFirst}{wxdirgetfirst}.
128
94f562a2 129\membersection{wxDir::Traverse}\label{wxdirtraverse}
35332784
VZ
130
131\func{size\_t}{Traverse}{\param{wxDirTraverser& }{sink}, \param{const wxString& }{filespec = wxEmptyString}, \param{int }{flags = wxDIR\_DEFAULT}}
132
133Enumerate all files and directories under the given directory recursively
134calling the element of the provided \helpref{wxDirTraverser}{wxdirtraverser}
135object for each of them.
136
137More precisely, the function will really recurse into subdirectories if
138{\it flags} contains {\tt wxDIR\_DIRS} flag. It will ignore the files (but
139still possibly recurse into subdirectories) if {\tt wxDIR\_FILES} flag is
140given.
141
142For each found directory, \helpref{sink.OnDir()}{wxdirtraverserondir} is called
143and \helpref{sink.OnFile()}{wxdirtraverseronfile} is called for every file.
144Depending on the return value, the enumeration may continue or stop.
145
146The function returns the total number of files found or {\tt (size\_t)-1} on
147error.
148
2e64ba46 149See also: \helpref{GetAllFiles}{wxdirgetallfiles}
35332784 150
2e64ba46 151\membersection{wxDir::GetAllFiles}\label{wxdirgetallfiles}
35332784
VZ
152
153\func{static size\_t}{GetAllFiles}{\param{const wxString& }{dirname}, \param{wxArrayString *}{files}, \param{const wxString& }{filespec = wxEmptyString}, \param{int }{flags = wxDIR\_DEFAULT}}
154
155The function appends the names of all the files under directory {\it dirname}
156to the array {\it files} (note that its old contents is preserved). Only files
157matching the {\it filespec} are taken, with empty spec matching all the files.
158
159The {\it flags} parameter should always include {\tt wxDIR\_FILES} or the array
160would be unchanged and should include {\tt wxDIR\_DIRS} flag to recurse into
161subdirectories (both flags are included in the value by default).
162
163See also: \helpref{Traverse}{wxdirtraverse}
164
165\section{\class{wxDirTraverser}}\label{wxdirtraverser}
166
167wxDirTraverser is an abstract interface which must be implemented by objects
168passed to \helpref{Traverse}{wxdirtraverse} function.
169
170Example of use (this works almost like \helpref{GetAllFiles}{wxdirgetallfiles}):
171
172\begin{verbatim}
173 class wxDirTraverserSimple : public wxDirTraverser
174 {
175 public:
176 wxDirTraverserSimple(wxArrayString& files) : m_files(files) { }
177
178 virtual wxDirTraverseResult OnFile(const wxString& filename)
179 {
180 m_files.Add(filename);
181 return wxDIR_CONTINUE;
182 }
183
184 virtual wxDirTraverseResult OnDir(const wxString& WXUNUSED(dirname))
185 {
186 return wxDIR_CONTINUE;
187 }
188
189 private:
190 wxArrayString& m_files;
191 };
192
193 // get the names of all files in the array
194 wxArrayString files;
195 wxDirTraverserSimple traverser(files);
196
197 wxDir dir(dirname);
198 dir.Traverse(traverser);
199\end{verbatim}
200
201\wxheading{Derived from}
202
203No base class
204
205\wxheading{Constants}
206
207The elements of {\tt wxDirTraverseResult} are the possible return values of the
208callback functions:
209
210{\small
211\begin{verbatim}
212enum wxDirTraverseResult
213{
214 wxDIR_IGNORE = -1, // ignore this directory but continue with others
215 wxDIR_STOP, // stop traversing
216 wxDIR_CONTINUE // continue into this directory
217};
218\end{verbatim}
a096358c 219}
35332784
VZ
220
221\wxheading{Include files}
222
223<wx/dir.h>
224
225\latexignore{\rtfignore{\wxheading{Members}}}
226
94f562a2 227\membersection{wxDirTraverser::OnFile}\label{wxdirtraverseronfile}
35332784
VZ
228
229\func{virtual wxDirTraverseResult}{OnFile}{\param{const wxString& }{filename}}
230
231This function is called for each file. It may return {\tt wxDIR\_STOP} to abort
232traversing (for example, if the file being searched is found) or
233{\tt wxDIR\_CONTINUE} to proceed.
234
94f562a2 235\membersection{wxDirTraverser::OnDir}\label{wxdirtraverserondir}
35332784
VZ
236
237\func{virtual wxDirTraverseResult}{OnDir}{\param{const wxString& }{dirname}}
238
239This function is called for each directory. It may return {\tt wxSIR\_STOP}
240to abort traversing completely, {\tt wxDIR\_IGNORE} to skip this directory but
241continue with others or {\tt wxDIR\_CONTINUE} to enumerate all files and
242subdirectories in this directory.
243