29.07.2011 - fundamental new
This commit is contained in:
42
pidir.h
42
pidir.h
@@ -2,41 +2,67 @@
|
||||
#define PIDIR_H
|
||||
|
||||
#include "pifile.h"
|
||||
#ifndef WINDOWS
|
||||
#include <sys/dir.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
class PIDir
|
||||
{
|
||||
public:
|
||||
PIDir() {dir_ = 0;}
|
||||
PIDir();
|
||||
PIDir(const PIString & dir);
|
||||
~PIDir() {close();}
|
||||
|
||||
struct DirEntry {
|
||||
DirEntry() {;}
|
||||
DirEntry(const PIString & name_, const int & mode_, const int & size_) {
|
||||
name = name_; mode = mode_; size = size_;}
|
||||
|
||||
PIString name;
|
||||
int mode;
|
||||
int size;
|
||||
|
||||
bool isDir() const {return (mode & S_IFDIR);}
|
||||
bool isFile() const {return (mode & S_IFREG);}
|
||||
bool isSymLink() const {return (mode & S_IFLNK);}
|
||||
bool isBlkDevice() const {return (mode & S_IFBLK);}
|
||||
bool isChrDevice() const {return (mode & S_IFCHR);}
|
||||
bool isSocket() const {return (mode & S_IFSOCK);}
|
||||
};
|
||||
|
||||
inline const bool isExists() {return (dir_ != 0);}
|
||||
inline const bool isAbsolute() {if (path_.size() == 0) return false; return (path_[0] == separator);}
|
||||
inline PIString path() {return PIString(path_);}
|
||||
PIDir & cleanPath();
|
||||
inline PIDir cleanedPath() {PIDir d(path_); d.cleanPath(); return d;}
|
||||
PIString absolutePath();
|
||||
bool mkDir(bool withParents = true);
|
||||
PIVector<DirEntry> entries();
|
||||
|
||||
PIDir & cd(const PIString & path);
|
||||
inline PIDir & up() {return cd("..");}
|
||||
|
||||
bool operator ==(const PIDir & d) const;
|
||||
|
||||
#ifdef WINDOWS
|
||||
static const char separator = '\\';
|
||||
#else
|
||||
static const char separator = '/';
|
||||
#endif
|
||||
static const PIChar separator;
|
||||
|
||||
static PIDir current();
|
||||
static PIDir home();
|
||||
static PIDir temporary();
|
||||
static bool mkDir(const PIString & path);
|
||||
static bool mkDir(const PIString & path, bool withParents = true);
|
||||
static bool rmDir(const PIString & path);
|
||||
static bool isExists(const PIString & path) {return PIDir(path).isExists();}
|
||||
//static bool rmDir(const PIString & path);
|
||||
|
||||
private:
|
||||
bool open();
|
||||
bool close();
|
||||
|
||||
string path_;
|
||||
PIString path_;
|
||||
|
||||
DIR * dir_;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif // PIDIR_H
|
||||
|
||||
Reference in New Issue
Block a user