/* PIP - Platform Independent Primitives Directory Copyright (C) 2011 Ivan Pelipenko peri4@rambler.ru This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef PIDIR_H #define PIDIR_H #include "pifile.h" #ifndef WINDOWS #include #include class PIDir { public: 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 entries(); PIDir & cd(const PIString & path); inline PIDir & up() {return cd("..");} bool operator ==(const PIDir & d) const; static const PIChar separator; static PIDir current(); static PIDir home(); static PIDir temporary(); 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(); PIString path_; DIR * dir_; }; #endif #endif // PIDIR_H