17 #ifndef DIRECTORYSCANNER_H_ 18 #define DIRECTORYSCANNER_H_ 23 #define DIRSCAN_OPENDIR_ERROR DIRSCAN_ERROR_OFFSET-1 24 #define DIRSCAN_CLOSEDIR_ERROR DIRSCAN_ERROR_OFFSET-2 25 #define DIRSCAN_NOTOPEN_ERROR DIRSCAN_ERROR_OFFSET-3 26 #define DIRSCAN_CREATEDIR_ERROR DIRSCAN_ERROR_OFFSET-4 27 #define DIRSCAN_DIRDOESNTEXIST_ERROR DIRSCAN_ERROR_OFFSET-5 31 #if defined(_MSC_VER) || defined(__MINGW32__) 90 int open(std::string path) {
95 char *errStr=strerror(errno);
107 char *errStr=strerror(errno);
119 int findAll(
const std::vector<std::string> &dontInclude) {
124 while (ent =
readdir(dir), ent != NULL) {
127 for (
unsigned int i=0; i<dontInclude.size(); i++){
129 if (strcmp(dontInclude[i].c_str(), ent->
d_name)==0) {
135 push_back(std::string(ent->
d_name));
154 for (
int i=
size()-1; i>=0; i--)
155 if (
operator[](i).find(pattern)==std::string::npos)
166 #if !defined(_MSC_VER) && !defined(__MINGW32__) 171 struct passwd *pw = getpwuid(getuid());
173 return std::string(pw->pw_dir);
175 return std::string();
181 #if !defined(_MSC_VER) && !defined(__MINGW32__) 182 static int mkDir(
const std::string &pathname, mode_t mode){
184 std::string cmd(
"mkdir -p ");
186 printf(
"%s\n",cmd.c_str());
187 int ret=system(cmd.c_str());
190 int res=mkdir(pathname.c_str(), mode);
201 if (res==ENAMETOOLONG)
219 return DirectoryScannerDebug().evaluateError(
DIRSCAN_CREATEDIR_ERROR, pathname+
". The parent directory does not allow write permission to the process, or one of the directories in pathname did not allow search permission.");
224 static int mkDir(
const std::string &pathname) {
226 int res=_mkdir(pathname.c_str());
236 #endif // DIRECTORYSCANNER_H_
static std::string getHomeDir()
static DIR * opendir(const char *dirname)
#define DIRSCAN_NOTOPEN_ERROR
Error when the directory hasn't been open yet.
std::map< int, std::string > errors
This will contain a map between error numbers and descriptive std::strings for the errors...
#define NO_ERROR
There is no error.
DirectoryScanner(std::string path)
#define DIRSCAN_CREATEDIR_ERROR
Error when the directory hasn't been open yet.
int open(std::string path)
int findAll(const std::vector< std::string > &dontInclude)
virtual ~DirectoryScanner()
static struct dirent * readdir(DIR *dirp)
#define DIRSCAN_DIRDOESNTEXIST_ERROR
Error when the directory hasn't been open yet.
static void rewinddir(DIR *dirp)
#define DIRSCAN_CLOSEDIR_ERROR
Error when the specified dir doesn't close successfully.
void keepWithPattern(const std::string pattern)
static int closedir(DIR *dirp)
static int mkDir(const std::string &pathname, mode_t mode)
#define DIRSCAN_OPENDIR_ERROR
Error when the specified directory can't be found.