]> git.saurik.com Git - wxWidgets.git/blame - include/wx/dir.h
removed tons of unused stuff apparently copied verbatim from MS headers (argh!!)...
[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
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:
57 // called for each file found by wxDir::Traverse()
58 //
350777b6
VZ
59 // return wxDIR_STOP or wxDIR_CONTINUE from here (wxDIR_IGNORE doesn't
60 // make sense)
35332784
VZ
61 virtual wxDirTraverseResult OnFile(const wxString& filename) = 0;
62
63 // called for each directory found by wxDir::Traverse()
64 //
65 // return one of the enum elements defined above
66 virtual wxDirTraverseResult OnDir(const wxString& dirname) = 0;
350777b6
VZ
67
68 // called for each directory which we couldn't open during our traversal
69 // of the directory tyree
70 //
71 // this method can also return either wxDIR_STOP, wxDIR_IGNORE or
72 // wxDIR_CONTINUE but the latter is treated specially: it means to retry
73 // opening the directory and so may lead to infinite loop if it is
74 // returned unconditionally, be careful with this!
75 //
76 // the base class version always returns wxDIR_IGNORE
77 virtual wxDirTraverseResult OnOpenError(const wxString& dirname);
35332784
VZ
78};
79
1944c6bd
VZ
80// ----------------------------------------------------------------------------
81// wxDir: portable equivalent of {open/read/close}dir functions
82// ----------------------------------------------------------------------------
83
bddd7a8d 84class WXDLLIMPEXP_BASE wxDirData;
fbfb3fb3 85
bddd7a8d 86class WXDLLIMPEXP_BASE wxDir
1944c6bd
VZ
87{
88public:
89 // test for existence of a directory with the given name
90 static bool Exists(const wxString& dir);
91
92 // ctors
93 // -----
94
95 // default, use Open()
96 wxDir() { m_data = NULL; }
97
98 // opens the directory for enumeration, use IsOpened() to test success
99 wxDir(const wxString& dir);
100
101 // dtor cleans up the associated ressources
102 ~wxDir();
103
104 // open the directory for enumerating
105 bool Open(const wxString& dir);
106
107 // returns TRUE if the directory was successfully opened
108 bool IsOpened() const;
109
35332784
VZ
110 // get the full name of the directory (without '/' at the end)
111 wxString GetName() const;
112
1944c6bd
VZ
113 // file enumeration routines
114 // -------------------------
115
116 // start enumerating all files matching filespec (or all files if it is
117 // empty) and flags, return TRUE on success
118 bool GetFirst(wxString *filename,
119 const wxString& filespec = wxEmptyString,
120 int flags = wxDIR_DEFAULT) const;
121
d9ff0f91 122 // get next file in the enumeration started with GetFirst()
1944c6bd
VZ
123 bool GetNext(wxString *filename) const;
124
d9ff0f91 125 // return true if this directory has any files in it
1357a7dd 126 bool HasFiles(const wxString& spec = wxEmptyString);
d9ff0f91
VZ
127
128 // return true if this directory has any subdirectories
1357a7dd 129 bool HasSubDirs(const wxString& spec = wxEmptyString);
d9ff0f91 130
35332784 131 // enumerate all files in this directory and its subdirectories
1944c6bd 132 //
35332784
VZ
133 // return the number of files found
134 size_t Traverse(wxDirTraverser& sink,
135 const wxString& filespec = wxEmptyString,
136 int flags = wxDIR_DEFAULT) const;
137
138 // simplest version of Traverse(): get the names of all files under this
139 // directory into filenames array, return the number of files
140 static size_t GetAllFiles(const wxString& dirname,
141 wxArrayString *files,
142 const wxString& filespec = wxEmptyString,
143 int flags = wxDIR_DEFAULT);
1944c6bd
VZ
144
145private:
886dd7d2 146 friend class wxDirData;
1944c6bd
VZ
147
148 wxDirData *m_data;
22f3361e
VZ
149
150 DECLARE_NO_COPY_CLASS(wxDir)
1944c6bd
VZ
151};
152
153#endif // _WX_DIR_H_
886dd7d2 154