From 2211428f2d3de7da6e057624e43dc8d13a106a54 Mon Sep 17 00:00:00 2001 From: fluxgen Date: Sun, 17 Aug 2003 13:19:54 +0000 Subject: added isDirectory and isRegularFile --- src/FbTk/Directory.cc | 21 ++++++++++++++++++++- src/FbTk/Directory.hh | 7 +++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/FbTk/Directory.cc b/src/FbTk/Directory.cc index 8d327dd..5ec5c0c 100644 --- a/src/FbTk/Directory.cc +++ b/src/FbTk/Directory.cc @@ -19,10 +19,13 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Directory.cc,v 1.1 2003/05/18 22:06:59 fluxgen Exp $ +// $Id: Directory.cc,v 1.2 2003/08/17 13:19:54 fluxgen Exp $ #include "Directory.hh" +#include +#include + namespace FbTk { Directory::Directory(const char *dir):m_dir(0), @@ -83,4 +86,20 @@ bool Directory::open(const char *dir) { return true; } +bool Directory::isDirectory(const std::string &filename) { + struct stat statbuf; + if (stat(filename.c_str(), &statbuf) != 0) + return false; + + return S_ISDIR(statbuf.st_mode); +} + +bool Directory::isRegularFile(const std::string &filename) { + struct stat statbuf; + if (stat(filename.c_str(), &statbuf) != 0) + return false; + + return S_ISREG(statbuf.st_mode); +} + }; // end namespace FbTk diff --git a/src/FbTk/Directory.hh b/src/FbTk/Directory.hh index 0786214..7862a51 100644 --- a/src/FbTk/Directory.hh +++ b/src/FbTk/Directory.hh @@ -19,7 +19,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Directory.hh,v 1.1 2003/05/18 22:06:59 fluxgen Exp $ +// $Id: Directory.hh,v 1.2 2003/08/17 13:19:54 fluxgen Exp $ #ifndef FBTK_DIRECTORY_HH #define FBTK_DIRECTORY_HH @@ -51,7 +51,10 @@ public: bool open(const char *dir); /// @return number of entries in the directory size_t entries() const { return m_num_entries; } - + /// @return true if file is a directory + static bool isDirectory(const std::string &filename); + /// @return true if a file is a regular file + static bool isRegularFile(const std::string &filename); private: DIR *m_dir; size_t m_num_entries; ///< number of file entries in directory -- cgit v0.11.2