]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dir.h
previous commit removed WXDLLIMPEXP_HTML by mistake
[wxWidgets.git] / include / wx / dir.h
CommitLineData
1944c6bd
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/dir.h
3// Purpose: wxDir is a class for enumerating the files in a directory
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 08.12.99
7// RCS-ID: $Id$
8// Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
371a5b4e 9// Licence: wxWindows licence
1944c6bd
VZ
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_DIR_H_
13#define _WX_DIR_H_
14
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
1944c6bd
VZ
16 #pragma interface "dir.h"
17#endif
18
19#ifndef WX_PRECOMP
20 #include "wx/string.h"
df5168c4 21 #include "wx/arrstr.h"
1944c6bd
VZ
22#endif
23
24// ----------------------------------------------------------------------------
25// constants
26// ----------------------------------------------------------------------------
27
28// these flags define what kind of filenames is included in the list of files
29// enumerated by GetFirst/GetNext
30enum
31{
32 wxDIR_FILES = 0x0001, // include files
33 wxDIR_DIRS = 0x0002, // include directories
34 wxDIR_HIDDEN = 0x0004, // include hidden files
35 wxDIR_DOTDOT = 0x0008, // include '.' and '..'
36
37 // by default, enumerate everything except '.' and '..'
38 wxDIR_DEFAULT = wxDIR_FILES | wxDIR_DIRS | wxDIR_HIDDEN
39};
40
35332784
VZ
41// these constants are possible return value of wxDirTraverser::OnDir()
42enum wxDirTraverseResult
43{
44 wxDIR_IGNORE = -1, // ignore this directory but continue with others
45 wxDIR_STOP, // stop traversing
46 wxDIR_CONTINUE // continue into this directory
47};
48
49// ----------------------------------------------------------------------------
50// wxDirTraverser: helper class for wxDir::Traverse()
51// ----------------------------------------------------------------------------
52
bddd7a8d 53class WXDLLIMPEXP_BASE wxDirTraverser
35332784
VZ
54{
55public:
56 // called for each file found by wxDir::Traverse()
57 //
350777b6
VZ
58 // return wxDIR_STOP or wxDIR_CONTINUE from here (wxDIR_IGNORE doesn't
59 // make sense)
35332784
VZ
60 virtual wxDirTraverseResult OnFile(const wxString& filename) = 0;
61
62 // called for each directory found by wxDir::Traverse()
63 //
64 // return one of the enum elements defined above
65 virtual wxDirTraverseResult OnDir(const wxString& dirname) = 0;
350777b6
VZ
66
67 // called for each directory which we couldn't open during our traversal
68 // of the directory tyree
69 //
70 // this method can also return either wxDIR_STOP, wxDIR_IGNORE or
71 // wxDIR_CONTINUE but the latter is treated specially: it means to retry
72 // opening the directory and so may lead to infinite loop if it is
73 // returned unconditionally, be careful with this!
74 //
75 // the base class version always returns wxDIR_IGNORE
76 virtual wxDirTraverseResult OnOpenError(const wxString& dirname);
35332784
VZ
77};
78
1944c6bd
VZ
79// ----------------------------------------------------------------------------
80// wxDir: portable equivalent of {open/read/close}dir functions
81// ----------------------------------------------------------------------------
82
bddd7a8d 83class WXDLLIMPEXP_BASE wxDirData;
fbfb3fb3 84
bddd7a8d 85class WXDLLIMPEXP_BASE wxDir
1944c6bd
VZ
86{
87public:
88 // test for existence of a directory with the given name
89 static bool Exists(const wxString& dir);
90
91 // ctors
92 // -----
93
94 // default, use Open()
95 wxDir() { m_data = NULL; }
96
97 // opens the directory for enumeration, use IsOpened() to test success
98 wxDir(const wxString& dir);
99
100 // dtor cleans up the associated ressources
101 ~wxDir();
102
103 // open the directory for enumerating
104 bool Open(const wxString& dir);
105
106 // returns TRUE if the directory was successfully opened
107 bool IsOpened() const;
108
35332784
VZ
109 // get the full name of the directory (without '/' at the end)
110 wxString GetName() const;
111
1944c6bd
VZ
112 // file enumeration routines
113 // -------------------------
114
115 // start enumerating all files matching filespec (or all files if it is
116 // empty) and flags, return TRUE on success
117 bool GetFirst(wxString *filename,
118 const wxString& filespec = wxEmptyString,
119 int flags = wxDIR_DEFAULT) const;
120
d9ff0f91 121 // get next file in the enumeration started with GetFirst()
1944c6bd
VZ
122 bool GetNext(wxString *filename) const;
123
d9ff0f91 124 // return true if this directory has any files in it
1357a7dd 125 bool HasFiles(const wxString& spec = wxEmptyString);
d9ff0f91
VZ
126
127 // return true if this directory has any subdirectories
1357a7dd 128 bool HasSubDirs(const wxString& spec = wxEmptyString);
d9ff0f91 129
35332784 130 // enumerate all files in this directory and its subdirectories
1944c6bd 131 //
35332784
VZ
132 // return the number of files found
133 size_t Traverse(wxDirTraverser& sink,
134 const wxString& filespec = wxEmptyString,
135 int flags = wxDIR_DEFAULT) const;
136
137 // simplest version of Traverse(): get the names of all files under this
138 // directory into filenames array, return the number of files
139 static size_t GetAllFiles(const wxString& dirname,
140 wxArrayString *files,
141 const wxString& filespec = wxEmptyString,
142 int flags = wxDIR_DEFAULT);
1944c6bd
VZ
143
144private:
886dd7d2 145 friend class wxDirData;
1944c6bd
VZ
146
147 wxDirData *m_data;
22f3361e
VZ
148
149 DECLARE_NO_COPY_CLASS(wxDir)
1944c6bd
VZ
150};
151
152#endif // _WX_DIR_H_
886dd7d2 153