diff --git a/mrw/file.hpp b/mrw/file.hpp
index 98e7885..96b6be0 100644
--- a/mrw/file.hpp
+++ b/mrw/file.hpp
@@ -1,4 +1,3 @@
-
/** @file
$Id$
@@ -10,6 +9,9 @@
@license LGPL, see file COPYING
$Log$
+ Revision 1.4 2005/02/28 07:17:24 marc
+ Dir is now usable and compilable, also added fixes for Solaris
+
Revision 1.3 2005/02/18 15:52:20 marc
correection in documentation
@@ -27,6 +29,7 @@
#define __MRW_FILE_HPP__
#include
+#include
#include
#include
#include
@@ -154,15 +157,42 @@ namespace mrw {
+filename+"'");
return sz;
}
+
+ /** @brief Remove a file
+
+ Remove a file
+
+ @throw mrw::unix_error in case of failure,
+ i.e. if the file does not exist
+ @param file the file name
+ */
+ static void remove(const std::string& file) throw(std::exception) {
+ if (unlink(file.c_str()))
+ throw mrw::unix_error("Cannot remove file "+file);
+ }
};
//============================================================================
+ /** @brief Directory access
+
+ Parse through directories:
+
+ @code
+ mrw::Dir dir(mrw::ifelse(getenv("HOME"), ""));
+ while (dir) {
+ std::cout<<"Found ["<. and
+ @param ignoreDots ignore directories .
and
..
(self anf top)
*/
Dir(const std::string& dir, bool ignoreDots=true) throw(std::exception):
@@ -275,8 +354,10 @@ namespace mrw {
operator bool() throw() {
static const std::string D("."), DD("..");
static dirent* fake;
- if (readdir_r(_dir, &_entry.entry(), &fake)) return false;
- if (_ignoreDots && _entry==Entry::DIR && (D==_entry() || D==_entry()))
+ if (readdir_r(_dir, &_entry.entry(), &fake) || !fake) return false;
+ if (_ignoreDots
+ && (_entry.type()==Entry::UNKNOWN || _entry.type()==Entry::DIR)
+ && (D==_entry() || DD==_entry()))
return operator bool();
return true;
}