wxDir is a portable equivalent of Unix open/read/closedir functions which allow enumerating of the files in a directory. wxDir allows enumerate files as well as directories.
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("%s\n", filename.c_str()); cont = dir.GetNext(&filename); }Derived from
No base class
Constants
These flags define what kind of filenames is included in the list of files enumerated by GetFirst/GetNext
enum
{
wxDIR_FILES = 0x0001, // include files
wxDIR_DIRS = 0x0002, // include directories
wxDIR_HIDDEN = 0x0004, // include hidden files
wxDIR_DOTDOT = 0x0008, // include '.' and '..'
// by default, enumerate everything except '.' and '..'
wxDIR_DEFAULT = wxDIR_FILES | wxDIR_DIRS | wxDIR_HIDDEN
}
Include files
<wx/dir.h>
Members
wxDir::Exists
wxDir::wxDir
wxDir::~wxDir
wxDir::Open
wxDir::IsOpened
wxDir::GetFirst
wxDir::GetNext
static bool Exists(const wxString& dir)
Test for existence of a directory with the given name
wxDir()
Default constructor, use Open() afterwards.
wxDir(const wxString& dir)
Opens the directory for enumeration, use IsOpened() to test for errors.
~wxDir()
Destructor cleans up the associated ressources. It is not virtual and so this class is not meant to be used polymorphically.
bool Open(const wxString& dir)
Open the directory for enumerating, returns TRUE on success or FALSE if an error occurred.
bool IsOpened() const
Returns TRUE if the directory was successfully opened by a previous call to Open.
bool GetFirst(wxString* filename, const wxString& filespec = wxEmptyString, int flags = wxDIR_DEFAULT) const
Start enumerating all files matching filespec (or all files if it is empty) and flags, return TRUE on success.
bool GetNext(wxString* filename) const
Continue enumerating files satisfying the criteria specified by the last call to GetFirst.