]>
Commit | Line | Data |
---|---|---|
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 | ||
14 | wxDir is a portable equivalent of Unix {open/read/close}dir functions which | |
15 | allow enumerating of the files in a directory. wxDir allows enumerate files as | |
16 | well as directories. | |
17 | ||
35332784 VZ |
18 | wxDir 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 |
22 | Example 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 | ||
49 | No base class | |
50 | ||
51 | \wxheading{Constants} | |
52 | ||
e00a5d3c JS |
53 | These flags define what kind of filename is included in the list of files |
54 | enumerated by GetFirst/GetNext. | |
4afd7529 VZ |
55 | |
56 | {\small | |
57 | \begin{verbatim} | |
58 | enum | |
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 | ||
4afd7529 VZ |
77 | \membersection{wxDir::wxDir}\label{wxdirwxdir} |
78 | ||
79 | \func{}{wxDir}{\void} | |
80 | ||
81 | Default constructor, use \helpref{Open()}{wxdiropen} afterwards. | |
82 | ||
83 | \func{}{wxDir}{\param{const wxString\& }{dir}} | |
84 | ||
85 | Opens the directory for enumeration, use \helpref{IsOpened()}{wxdirisopened} | |
86 | to test for errors. | |
87 | ||
55427034 | 88 | |
4afd7529 VZ |
89 | \membersection{wxDir::\destruct{wxDir}}\label{wxdirdtor} |
90 | ||
91 | \func{}{\destruct{wxDir}}{\void} | |
92 | ||
2edb0bde | 93 | Destructor cleans up the associated resources. It is not virtual and so this |
4afd7529 VZ |
94 | class is not meant to be used polymorphically. |
95 | ||
4afd7529 | 96 | |
55427034 | 97 | \membersection{wxDir::Exists}\label{wxdirexists} |
4afd7529 | 98 | |
55427034 | 99 | \func{static bool}{Exists}{\param{const wxString\& }{dir}} |
4afd7529 | 100 | |
55427034 | 101 | Test for existence of a directory with the given name |
4afd7529 | 102 | |
4afd7529 | 103 | |
55427034 VZ |
104 | \membersection{wxDir::GetAllFiles}\label{wxdirgetallfiles} |
105 | ||
106 | \func{static size\_t}{GetAllFiles}{\param{const wxString\& }{dirname}, \param{wxArrayString *}{files}, \param{const wxString\& }{filespec = wxEmptyString}, \param{int }{flags = wxDIR\_DEFAULT}} | |
107 | ||
108 | The function appends the names of all the files under directory {\it dirname} | |
109 | to the array {\it files} (note that its old contents is preserved). Only files | |
110 | matching the {\it filespec} are taken, with empty spec matching all the files. | |
111 | ||
112 | The {\it flags} parameter should always include {\tt wxDIR\_FILES} or the array | |
113 | would be unchanged and should include {\tt wxDIR\_DIRS} flag to recurse into | |
114 | subdirectories (both flags are included in the value by default). | |
115 | ||
116 | See also: \helpref{Traverse}{wxdirtraverse} | |
117 | ||
4afd7529 VZ |
118 | |
119 | \membersection{wxDir::GetFirst}\label{wxdirgetfirst} | |
120 | ||
121 | \constfunc{bool}{GetFirst}{\param{wxString* }{filename}, \param{const wxString\& }{filespec = wxEmptyString}, \param{int }{flags = wxDIR\_DEFAULT}} | |
122 | ||
123 | Start enumerating all files matching {\it filespec} (or all files if it is | |
cc81d32f | 124 | empty) and flags, return true on success. |
4afd7529 | 125 | |
55427034 VZ |
126 | |
127 | \membersection{wxDir::GetName}\label{wxdirgetname} | |
128 | ||
129 | \constfunc{wxString}{GetName}{\void} | |
130 | ||
131 | Returns the name of the directory itself. The returned string does not have the | |
132 | trailing path separator (slash or backslash). | |
133 | ||
134 | ||
4afd7529 VZ |
135 | \membersection{wxDir::GetNext}\label{wxdirgetnext} |
136 | ||
137 | \constfunc{bool}{GetNext}{\param{wxString* }{filename}} | |
138 | ||
139 | Continue enumerating files satisfying the criteria specified by the last call | |
140 | to \helpref{GetFirst}{wxdirgetfirst}. | |
141 | ||
55427034 | 142 | |
d9ff0f91 VZ |
143 | \membersection{wxDir::HasFiles}\label{wxdirhasfiles} |
144 | ||
7af3ca16 | 145 | \func{bool}{HasFiles}{\param{const wxString\& }{filespec = wxEmptyString}} |
d9ff0f91 | 146 | |
cc81d32f | 147 | Returns {\tt true} if the directory contains any files matching the given |
d9ff0f91 VZ |
148 | {\it filespec}. If {\it filespec} is empty, look for any files at all. In any |
149 | case, even hidden files are taken into account. | |
150 | ||
55427034 | 151 | |
d9ff0f91 VZ |
152 | \membersection{wxDir::HasSubDirs}\label{wxdirhassubdirs} |
153 | ||
7af3ca16 | 154 | \func{bool}{HasSubDirs}{\param{const wxString\& }{dirspec = wxEmptyString}} |
d9ff0f91 | 155 | |
cc81d32f | 156 | Returns {\tt true} if the directory contains any subdirectories (if a non |
d9ff0f91 VZ |
157 | empty {\it filespec} is given, only check for directories matching it). |
158 | The hidden subdirectories are taken into account as well. | |
159 | ||
55427034 VZ |
160 | |
161 | \membersection{wxDir::IsOpened}\label{wxdirisopened} | |
162 | ||
163 | \constfunc{bool}{IsOpened}{\void} | |
164 | ||
165 | Returns true if the directory was successfully opened by a previous call to | |
166 | \helpref{Open}{wxdiropen}. | |
167 | ||
168 | ||
169 | \membersection{wxDir::Open}\label{wxdiropen} | |
170 | ||
171 | \func{bool}{Open}{\param{const wxString\& }{dir}} | |
172 | ||
173 | Open the directory for enumerating, returns true on success or false if an | |
174 | error occurred. | |
175 | ||
176 | ||
94f562a2 | 177 | \membersection{wxDir::Traverse}\label{wxdirtraverse} |
35332784 | 178 | |
7af3ca16 | 179 | \func{size\_t}{Traverse}{\param{wxDirTraverser\& }{sink}, \param{const wxString\& }{filespec = wxEmptyString}, \param{int }{flags = wxDIR\_DEFAULT}} |
35332784 VZ |
180 | |
181 | Enumerate all files and directories under the given directory recursively | |
182 | calling the element of the provided \helpref{wxDirTraverser}{wxdirtraverser} | |
183 | object for each of them. | |
184 | ||
185 | More precisely, the function will really recurse into subdirectories if | |
186 | {\it flags} contains {\tt wxDIR\_DIRS} flag. It will ignore the files (but | |
187 | still possibly recurse into subdirectories) if {\tt wxDIR\_FILES} flag is | |
188 | given. | |
189 | ||
190 | For each found directory, \helpref{sink.OnDir()}{wxdirtraverserondir} is called | |
191 | and \helpref{sink.OnFile()}{wxdirtraverseronfile} is called for every file. | |
192 | Depending on the return value, the enumeration may continue or stop. | |
193 | ||
194 | The function returns the total number of files found or {\tt (size\_t)-1} on | |
195 | error. | |
196 | ||
2e64ba46 | 197 | See also: \helpref{GetAllFiles}{wxdirgetallfiles} |
35332784 | 198 |