added name and isExecutable, patch from Mathias Gumz
This commit is contained in:
parent
bb2f1c8713
commit
95c20b15f9
2 changed files with 20 additions and 2 deletions
|
@ -19,7 +19,7 @@
|
|||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
|
||||
// $Id: Directory.cc,v 1.2 2003/08/17 13:19:54 fluxgen Exp $
|
||||
// $Id: Directory.cc,v 1.3 2004/04/19 18:09:15 fluxgen Exp $
|
||||
|
||||
#include "Directory.hh"
|
||||
|
||||
|
@ -60,6 +60,7 @@ std::string Directory::readFilename() {
|
|||
void Directory::close() {
|
||||
if (m_dir != 0) {
|
||||
closedir(m_dir);
|
||||
m_name.clear();
|
||||
m_dir = 0;
|
||||
m_num_entries = 0;
|
||||
}
|
||||
|
@ -77,6 +78,8 @@ bool Directory::open(const char *dir) {
|
|||
if (m_dir == 0) // successfull loading?
|
||||
return false;
|
||||
|
||||
m_name= dir;
|
||||
|
||||
// get number of entries
|
||||
while (read())
|
||||
m_num_entries++;
|
||||
|
@ -102,4 +105,14 @@ bool Directory::isRegularFile(const std::string &filename) {
|
|||
return S_ISREG(statbuf.st_mode);
|
||||
}
|
||||
|
||||
bool Directory::isExecutable(const std::string &filename) {
|
||||
struct stat statbuf;
|
||||
if (stat(filename.c_str(), &statbuf) != 0)
|
||||
return false;
|
||||
|
||||
return statbuf.st_mode & S_IXUSR ||
|
||||
statbuf.st_mode & S_IXGRP ||
|
||||
statbuf.st_mode & S_IXOTH;
|
||||
}
|
||||
|
||||
}; // end namespace FbTk
|
||||
|
|
|
@ -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.3 2003/12/16 17:06:49 fluxgen Exp $
|
||||
// $Id: Directory.hh,v 1.4 2004/04/19 18:09:14 fluxgen Exp $
|
||||
|
||||
#ifndef FBTK_DIRECTORY_HH
|
||||
#define FBTK_DIRECTORY_HH
|
||||
|
@ -37,6 +37,7 @@ class Directory: private FbTk::NotCopyable {
|
|||
public:
|
||||
explicit Directory(const char *dir = 0);
|
||||
~Directory();
|
||||
const std::string &name() const { return m_name; }
|
||||
/// go to start of filelist
|
||||
void rewind();
|
||||
/// gets next dirent info struct in directory and
|
||||
|
@ -55,7 +56,11 @@ public:
|
|||
static bool isDirectory(const std::string &filename);
|
||||
/// @return true if a file is a regular file
|
||||
static bool isRegularFile(const std::string &filename);
|
||||
/// @return true if a file executable for user
|
||||
static bool isExecutable(const std::string &filename);
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
DIR *m_dir;
|
||||
size_t m_num_entries; ///< number of file entries in directory
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue