Overview
Comment: | Add +[directoryExistsAtPath:] and +[filesInDirectoryAtPath:] to OFFile. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
8d84aa00aafba49448d87da40d28e48a |
User & Date: | js on 2010-04-15 08:11:22 |
Other Links: | manifest | tags |
Context
2010-04-15
| ||
08:43 | Add OFCreateDirectoryFailedException. check-in: ffc622db15 user: js tags: trunk | |
08:11 | Add +[directoryExistsAtPath:] and +[filesInDirectoryAtPath:] to OFFile. check-in: 8d84aa00aa user: js tags: trunk | |
2010-04-11
| ||
20:41 | Better names for a few file operations. check-in: 5f222e25a7 user: js tags: trunk | |
Changes
Modified src/OFFile.h from [f110a6ebca] to [658c0aafbb].
︙ | ︙ | |||
10 11 12 13 14 15 16 17 18 19 20 21 22 23 | */ #include <sys/types.h> #import "OFSeekableStream.h" @class OFString; /** * \brief A class which provides functions to read, write and manipulate files. */ @interface OFFile: OFSeekableStream { int fd; | > | 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | */ #include <sys/types.h> #import "OFSeekableStream.h" @class OFString; @class OFArray; /** * \brief A class which provides functions to read, write and manipulate files. */ @interface OFFile: OFSeekableStream { int fd; |
︙ | ︙ | |||
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | * \param fd A file descriptor, returned from for example open(). * It is not closed when the OFFile object is deallocated! * \return A new autoreleased OFFile */ + fileWithFileDescriptor: (int)fd; /** * \return A boolean whether there is a file at the specified path */ + (BOOL)fileExistsAtPath: (OFString*)path; /** * Changes the mode of a file. * * Only changes read-only flag on Windows. * * \param path The path to the file of which the mode should be changed as a * string | > > > > > > > > > > > > > | 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | * \param fd A file descriptor, returned from for example open(). * It is not closed when the OFFile object is deallocated! * \return A new autoreleased OFFile */ + fileWithFileDescriptor: (int)fd; /** * \param path The path to check * \return A boolean whether there is a file at the specified path */ + (BOOL)fileExistsAtPath: (OFString*)path; /** * \param path The path to check * \return A boolean whether there is a directory at the specified path */ + (BOOL)directoryExistsAtPath: (OFString*)path; /** * \param path The path of the directory * \return An array of OFStrings with the files at the specified path */ + (OFArray*)filesInDirectoryAtPath: (OFString*)path; /** * Changes the mode of a file. * * Only changes read-only flag on Windows. * * \param path The path to the file of which the mode should be changed as a * string |
︙ | ︙ |
Modified src/OFFile.m from [193ba08435] to [9b3c83ec11].
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #import "OFFile.h" #import "OFString.h" #import "OFExceptions.h" #ifdef _WIN32 # import <windows.h> #endif #ifndef O_BINARY | > > > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <stdio.h> #include <string.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <dirent.h> #import "OFFile.h" #import "OFString.h" #import "OFArray.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" #ifdef _WIN32 # import <windows.h> #endif #ifndef O_BINARY |
︙ | ︙ | |||
110 111 112 113 114 115 116 117 118 119 120 121 122 123 | return NO; if (S_ISREG(s.st_mode)) return YES; return NO; } + (void)changeModeOfFile: (OFString*)path toMode: (mode_t)mode { #ifndef _WIN32 if (chmod([path cString], mode)) @throw [OFChangeFileModeFailedException newWithClass: self | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 | return NO; 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 if (chmod([path cString], mode)) @throw [OFChangeFileModeFailedException newWithClass: self |
︙ | ︙ |