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