added isDirectory and isRegularFile

This commit is contained in:
fluxgen 2003-08-17 13:19:54 +00:00
parent 856ca4330f
commit 2211428f2d
2 changed files with 25 additions and 3 deletions

View file

@ -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 <sys/stat.h>
#include <unistd.h>
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

View file

@ -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