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