@@ -16,13 +16,16 @@ #include #include #include #include +#include #import "OFFile.h" #import "OFString.h" +#import "OFArray.h" +#import "OFAutoreleasePool.h" #import "OFExceptions.h" #ifdef _WIN32 # import #endif @@ -112,10 +115,61 @@ if (S_ISREG(s.st_mode)) return YES; return NO; } + ++ (BOOL)directoryExistsAtPath: (OFString*)path +{ + struct stat s; + + if (stat([path cString], &s) == -1) + return NO; + + if (S_ISDIR(s.st_mode)) + return YES; + + return NO; +} + ++ (OFArray*)filesInDirectoryAtPath: (OFString*)path +{ + OFAutoreleasePool *pool; + OFMutableArray *files; + DIR *dir; + struct dirent *dirent; + + files = [OFMutableArray array]; + + if ((dir = opendir([path cString])) == NULL) + @throw [OFOpenFileFailedException newWithClass: self + path: path + mode: @"r"]; + + @try { + pool = [[OFAutoreleasePool alloc] init]; + + while ((dirent = readdir(dir)) != NULL) { + OFString *file; + + if (!strcmp(dirent->d_name, ".") || + !strcmp(dirent->d_name, "..")) + continue; + + file = [OFString stringWithCString: dirent->d_name]; + [files addObject: file]; + + [pool releaseObjects]; + } + + [pool release]; + } @finally { + closedir(dir); + } + + return files; +} + (void)changeModeOfFile: (OFString*)path toMode: (mode_t)mode { #ifndef _WIN32