summaryrefslogtreecommitdiff
path: root/src/DirHelper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/DirHelper.cc')
-rw-r--r--src/DirHelper.cc33
1 files changed, 25 insertions, 8 deletions
diff --git a/src/DirHelper.cc b/src/DirHelper.cc
index 4098e3e..19f7612 100644
--- a/src/DirHelper.cc
+++ b/src/DirHelper.cc
@@ -19,11 +19,12 @@
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE. 20// DEALINGS IN THE SOFTWARE.
21 21
22// $Id: DirHelper.cc,v 1.1 2002/12/02 19:44:25 fluxgen Exp $ 22// $Id: DirHelper.cc,v 1.2 2003/02/15 01:42:17 fluxgen Exp $
23 23
24#include "DirHelper.hh" 24#include "DirHelper.hh"
25 25
26DirHelper::DirHelper(const char *dir):m_dir(0) { 26DirHelper::DirHelper(const char *dir):m_dir(0),
27m_num_entries(0) {
27 if (dir != 0) 28 if (dir != 0)
28 open(dir); 29 open(dir);
29} 30}
@@ -45,23 +46,39 @@ struct dirent *DirHelper::read() {
45 return readdir(m_dir); 46 return readdir(m_dir);
46} 47}
47 48
49std::string DirHelper::readFilename() {
50 dirent *ent = read();
51 if (ent == 0)
52 return "";
53 return (ent->d_name ? ent->d_name : "");
54}
55
48void DirHelper::close() { 56void DirHelper::close() {
49 if (m_dir != 0) { 57 if (m_dir != 0) {
50 closedir(m_dir); 58 closedir(m_dir);
51 m_dir = 0; 59 m_dir = 0;
60 m_num_entries = 0;
52 } 61 }
53} 62}
54 63
64
55bool DirHelper::open(const char *dir) { 65bool DirHelper::open(const char *dir) {
56 if (m_dir != 0)
57 close();
58 if (dir == 0) 66 if (dir == 0)
59 return false; 67 return false;
60 68
69 if (m_dir != 0)
70 close();
71
61 m_dir = opendir(dir); 72 m_dir = opendir(dir);
62 if (m_dir != 0) // successfull loading? 73 if (m_dir == 0) // successfull loading?
63 return true; 74 return false;
75
76 // get number of entries
77 while (read())
78 m_num_entries++;
79
80 rewind(); // go back to start
64 81
65 return false; 82 return true;
66} 83}
67 84