]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/dir.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDir is a class for enumerating the files in a directory
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1999 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "dir.h"
20 #include "wx/string.h"
23 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
27 // these flags define what kind of filenames is included in the list of files
28 // enumerated by GetFirst/GetNext
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 '..'
36 // by default, enumerate everything except '.' and '..'
37 wxDIR_DEFAULT
= wxDIR_FILES
| wxDIR_DIRS
| wxDIR_HIDDEN
40 // ----------------------------------------------------------------------------
41 // wxDir: portable equivalent of {open/read/close}dir functions
42 // ----------------------------------------------------------------------------
44 class WXDLLEXPORT wxDir
47 // test for existence of a directory with the given name
48 static bool Exists(const wxString
& dir
);
53 // default, use Open()
54 wxDir() { m_data
= NULL
; }
56 // opens the directory for enumeration, use IsOpened() to test success
57 wxDir(const wxString
& dir
);
59 // dtor cleans up the associated ressources
62 // open the directory for enumerating
63 bool Open(const wxString
& dir
);
65 // returns TRUE if the directory was successfully opened
66 bool IsOpened() const;
68 // file enumeration routines
69 // -------------------------
71 // start enumerating all files matching filespec (or all files if it is
72 // empty) and flags, return TRUE on success
73 bool GetFirst(wxString
*filename
,
74 const wxString
& filespec
= wxEmptyString
,
75 int flags
= wxDIR_DEFAULT
) const;
77 // get next file in the enumeration started with either GetFirst() or
79 bool GetNext(wxString
*filename
) const;
81 // TODO using scandir() when available later, emulating it otherwise
83 // get all files in the directory into an array, return TRUE on success
85 // this function uses Select() function to select the files
86 // unless the filespec is explicitly given and Compare() function to sort
88 bool Read(wxArrayString
& filenames
,
89 const wxString
& filespec
= wxEmptyString
) const;
92 // this function is called by Read() if filespec is not specified in
93 // Read(): it should return TRUE if the file matches our selection
94 // criteria and FALSE otherwise
95 virtual bool Select(const wxChar
* filename
);
97 // This function is called by Read() to sort the array: it should return
98 // -1, 0 or +1 if the first file is less than, equal to or greater than
99 // the second. The base class version does
100 virtual int Compare(const wxChar
*filename1
, const wxChar
*filename2
);
104 friend class WXDLLEXPORT wxDirData
;