Contents Up Previous Next

wxDirTraverser

wxDirTraverser is an abstract interface which must be implemented by objects passed to Traverse (REF NOT FOUND) function.

Example of use (this works almost like GetAllFiles (REF NOT FOUND)):

    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);
Derived from

No base class

Constants

The elements of wxDirTraverseResult are the possible return values of the callback functions:

enum wxDirTraverseResult
{
    wxDIR_IGNORE = -1,      // ignore this directory but continue with others
    wxDIR_STOP,             // stop traversing
    wxDIR_CONTINUE          // continue into this directory
};
Include files

<wx/dir.h>

Members

wxDirTraverser::OnFile
wxDirTraverser::OnDir


wxDirTraverser::OnFile

wxdirtraverseronfile

virtual wxDirTraverseResult OnFile(const wxString&filename)

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.


wxDirTraverser::OnDir

wxdirtraverserondir

virtual wxDirTraverseResult OnDir(const wxString&dirname)

This function is called for each directory. It may return wxSIR_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.