| Version: 3.3.1

Public Member Functions | List of all members
wxDirTraverser Class Referenceabstract
Class List by Category » File Handling

`#include <wx/dir.h>`

## Detailed Description

wxDirTraverser is an abstract interface which must be implemented by objects passed to wxDir::Traverse() function.

Example of use (this works almost like wxDir::GetAllFiles()):

class wxDirTraverserSimple : public wxDirTraverser
{
public:
wxDirTraverserSimple(wxArrayString& files) : m_files(files) { }
virtual wxDirTraverseResult OnFile(const wxString& filename)
{
m_files.Add(filename);
return wxDIR_CONTINUE;
}
virtual wxDirTraverseResult OnDir(const wxString& WXUNUSED(dirname))
{
return wxDIR_CONTINUE;
}
private:
wxArrayString& m_files;
};
// get the names of all files in the array
wxArrayString files;
wxDirTraverserSimple traverser(files);
wxDir dir(dirname);
dir.Traverse(traverser);
wxArrayString
wxArrayString is a legacy class similar to std::vector<wxString>.
Definition: arrstr.h:67
wxDir
wxDir is a portable equivalent of Unix open/read/closedir functions which allow enumerating of the fi...
Definition: dir.h:175
wxDirTraverser
wxDirTraverser is an abstract interface which must be implemented by objects passed to wxDir::Travers...
Definition: dir.h:64
wxDirTraverser::OnDir
virtual wxDirTraverseResult OnDir(const wxString &dirname)=0
This function is called for each directory.
wxDirTraverser::OnFile
virtual wxDirTraverseResult OnFile(const wxString &filename)=0
This function is called for each file.
wxString
String class for passing textual data to or receiving it from wxWidgets.
Definition: string.h:372
wxDirTraverseResult
wxDirTraverseResult
Possible return values of wxDirTraverser callback functions.
Definition: dir.h:12
wxDIR_CONTINUE
@ wxDIR_CONTINUE
Continue into this directory.
Definition: dir.h:15

##

Library: wxBase
Category: File Handling

## Public Member Functions
virtual wxDirTraverseResult | OnDir (const wxString &dirname)=0
| This function is called for each directory. More...
virtual wxDirTraverseResult | OnFile (const wxString &filename)=0
| This function is called for each file. More...
virtual wxDirTraverseResult | OnOpenError (const wxString &openerrorname)
| This function is called for each directory which we failed to open for enumerating. More...

## Member Function Documentation

## ◆ OnDir()

virtual wxDirTraverseResult wxDirTraverser::OnDir | ( | const wxString & | dirname | ) |
| pure virtual

This function is called for each directory.

It may return wxDIR_STOP to abort traversing completely, wxDIR_IGNORE to skip this directory but continue with others or wxDIR_CONTINUE to enumerate all files and subdirectories in this directory.

This is a pure virtual function and must be implemented in the derived class.

## ◆ OnFile()

virtual wxDirTraverseResult wxDirTraverser::OnFile | ( | const wxString & | filename | ) |
| pure virtual

This function is called for each file.

It may return wxDIR_STOP to abort traversing (for example, if the file being searched is found) or wxDIR_CONTINUE to proceed.

This is a pure virtual function and must be implemented in the derived class.

## ◆ OnOpenError()

virtual wxDirTraverseResult wxDirTraverser::OnOpenError | ( | const wxString & | openerrorname | ) |
| virtual

This function is called for each directory which we failed to open for enumerating.

It may return wxDIR_STOP to abort traversing completely, wxDIR_IGNORE to skip this directory but continue with others or wxDIR_CONTINUE to retry opening this directory once again.

The base class version always returns wxDIR_IGNORE.