]>
Commit | Line | Data |
---|---|---|
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> | |
9 | // Licence: wxWindows license | |
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" | |
21 | #endif | |
22 | ||
23 | // ---------------------------------------------------------------------------- | |
24 | // constants | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
27 | // these flags define what kind of filenames is included in the list of files | |
28 | // enumerated by GetFirst/GetNext | |
29 | enum | |
30 | { | |
31 | wxDIR_FILES = 0x0001, // include files | |
32 | wxDIR_DIRS = 0x0002, // include directories | |
33 | wxDIR_HIDDEN = 0x0004, // include hidden files | |
34 | wxDIR_DOTDOT = 0x0008, // include '.' and '..' | |
35 | ||
36 | // by default, enumerate everything except '.' and '..' | |
37 | wxDIR_DEFAULT = wxDIR_FILES | wxDIR_DIRS | wxDIR_HIDDEN | |
38 | }; | |
39 | ||
35332784 VZ |
40 | // these constants are possible return value of wxDirTraverser::OnDir() |
41 | enum wxDirTraverseResult | |
42 | { | |
43 | wxDIR_IGNORE = -1, // ignore this directory but continue with others | |
44 | wxDIR_STOP, // stop traversing | |
45 | wxDIR_CONTINUE // continue into this directory | |
46 | }; | |
47 | ||
48 | // ---------------------------------------------------------------------------- | |
49 | // wxDirTraverser: helper class for wxDir::Traverse() | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | class WXDLLEXPORT wxDirTraverser | |
53 | { | |
54 | public: | |
55 | // called for each file found by wxDir::Traverse() | |
56 | // | |
57 | // return wxDIR_STOP or wxDIR_CONTINUE from here | |
58 | virtual wxDirTraverseResult OnFile(const wxString& filename) = 0; | |
59 | ||
60 | // called for each directory found by wxDir::Traverse() | |
61 | // | |
62 | // return one of the enum elements defined above | |
63 | virtual wxDirTraverseResult OnDir(const wxString& dirname) = 0; | |
64 | }; | |
65 | ||
1944c6bd VZ |
66 | // ---------------------------------------------------------------------------- |
67 | // wxDir: portable equivalent of {open/read/close}dir functions | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
fbfb3fb3 VZ |
70 | class WXDLLEXPORT wxDirData; |
71 | ||
1944c6bd VZ |
72 | class WXDLLEXPORT wxDir |
73 | { | |
74 | public: | |
75 | // test for existence of a directory with the given name | |
76 | static bool Exists(const wxString& dir); | |
77 | ||
78 | // ctors | |
79 | // ----- | |
80 | ||
81 | // default, use Open() | |
82 | wxDir() { m_data = NULL; } | |
83 | ||
84 | // opens the directory for enumeration, use IsOpened() to test success | |
85 | wxDir(const wxString& dir); | |
86 | ||
87 | // dtor cleans up the associated ressources | |
88 | ~wxDir(); | |
89 | ||
90 | // open the directory for enumerating | |
91 | bool Open(const wxString& dir); | |
92 | ||
93 | // returns TRUE if the directory was successfully opened | |
94 | bool IsOpened() const; | |
95 | ||
35332784 VZ |
96 | // get the full name of the directory (without '/' at the end) |
97 | wxString GetName() const; | |
98 | ||
1944c6bd VZ |
99 | // file enumeration routines |
100 | // ------------------------- | |
101 | ||
102 | // start enumerating all files matching filespec (or all files if it is | |
103 | // empty) and flags, return TRUE on success | |
104 | bool GetFirst(wxString *filename, | |
105 | const wxString& filespec = wxEmptyString, | |
106 | int flags = wxDIR_DEFAULT) const; | |
107 | ||
d9ff0f91 | 108 | // get next file in the enumeration started with GetFirst() |
1944c6bd VZ |
109 | bool GetNext(wxString *filename) const; |
110 | ||
d9ff0f91 | 111 | // return true if this directory has any files in it |
1357a7dd | 112 | bool HasFiles(const wxString& spec = wxEmptyString); |
d9ff0f91 VZ |
113 | |
114 | // return true if this directory has any subdirectories | |
1357a7dd | 115 | bool HasSubDirs(const wxString& spec = wxEmptyString); |
d9ff0f91 | 116 | |
35332784 | 117 | // enumerate all files in this directory and its subdirectories |
1944c6bd | 118 | // |
35332784 VZ |
119 | // return the number of files found |
120 | size_t Traverse(wxDirTraverser& sink, | |
121 | const wxString& filespec = wxEmptyString, | |
122 | int flags = wxDIR_DEFAULT) const; | |
123 | ||
124 | // simplest version of Traverse(): get the names of all files under this | |
125 | // directory into filenames array, return the number of files | |
126 | static size_t GetAllFiles(const wxString& dirname, | |
127 | wxArrayString *files, | |
128 | const wxString& filespec = wxEmptyString, | |
129 | int flags = wxDIR_DEFAULT); | |
1944c6bd VZ |
130 | |
131 | private: | |
132 | friend class WXDLLEXPORT wxDirData; | |
133 | ||
134 | wxDirData *m_data; | |
22f3361e VZ |
135 | |
136 | DECLARE_NO_COPY_CLASS(wxDir) | |
1944c6bd VZ |
137 | }; |
138 | ||
139 | #endif // _WX_DIR_H_ |