.\" This is a wxWidgets manpage page generated from the XML docs .TH wxDir 3wx 2005-02-15 "wxWidgets" "wxWidgets class documentation" .SH NAME wxDir \- Class for enumerating files/subdirectories. .SH DESCRIPTION wxDir is a portable equivalent of Unix {open/read/close}dir functions which allow enumerating of the files in a directory. wxDir allows enumerate files as well as directories. wxDir also provides a flexible way to enumerate files recursively using Traverse or a simpler GetAllFiles function. Example of use: wxDir dir(wxGetCwd()); if ( !dir.IsOpened() ) { // deal with the error here - wxDir would already log an error message // explaining the exact reason of the failure return; } puts("Enumerating object files in current directory:"); wxString filename; bool cont = dir.GetFirst(&filename, filespec, flags); while ( cont ) { printf(" cont = dir.GetNext(&filename); } .SH "PARENTS" .SH "INCLUDE FILES" wx/dir.h .SH MEMBERS .SS wxDir () Default constructor, use Open() afterwards. .SS wxDir (const wxString& dir) Opens the directory for enumeration, use IsOpened() to test for errors. .SS ~wxDir () Destructor cleans up the associated resources. It is not virtual and so this class is not meant to be used polymorphically. .SS static bool Exists (const wxString& dir) Test for existence of a directory with the given name .SS static size_t GetAllFiles (const wxString& dirnamewxArrayString *filesconst wxString& filespec = wxEmptyStringint flags = wxDIR_DEFAULT) The function appends the names of all the files under directory dirname to the array files (note that its old content is preserved). Only files matching the filespec are taken, with empty spec matching all the files. The flags parameter should always include wxDIR_FILES or the array would be unchanged and should include wxDIR_DIRS flag to recurse into subdirectories (both flags are included in the value by default). See also Traverse .SS bool GetFirst (wxString* filenameconst wxString& filespec = wxEmptyStringint flags = wxDIR_DEFAULT) Start enumerating all files matching filespec (or all files if it is empty) and flags, return true on success. .SS wxString GetName () Returns the name of the directory itself. The returned string does not have the trailing path separator (slash or backslash). .SS bool GetNext (wxString* filename) Continue enumerating files satisfying the criteria specified by the last call to GetFirst . .SS bool HasFiles (const wxString& filespec = wxEmptyString) Returns true if the directory contains any files matching the given filespec . If filespec is empty, look for any files at all. In any case, even hidden files are taken into account. .SS bool HasSubDirs (const wxString& dirspec = wxEmptyString) Returns true if the directory contains any subdirectories (if a non empty filespec is given, only check for directories matching it). The hidden subdirectories are taken into account as well. .SS bool IsOpened () Returns true if the directory was successfully opened by a previous call to Open . .SS bool Open (const wxString& dir) Open the directory for enumerating, returns true on success or false if an error occurred. .SS size_t Traverse (wxDirTraverser& sinkconst wxString& filespec = wxEmptyStringint flags = wxDIR_DEFAULT) Enumerate all files and directories under the given directory recursively calling the element of the provided wxDirTraverser object for each of them. More precisely, the function will really recurse into subdirectories if flags contains wxDIR_DIRS flag. It will ignore the files (but still possibly recurse into subdirectories) if wxDIR_FILES flag is given. For each found directory, sink.OnDir() is called and sink.OnFile() is called for every file. Depending on the return value, the enumeration may continue or stop. The function returns the total number of files found or (size_t)-1 on error. See also GetAllFiles .SH "SEE ALSO" .SH "AUTHORS" Documentation content by Julian Smart, Robert Roebling, Vadim Zeitlin, Robin Dunn, et al Conversion to manpage format by Arnout Engelen (http://bzzt.net), bugreports welcome.