diff --git a/ChangeLog b/ChangeLog index f6c3586d5..2ce0d1f42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2010-06-22 David Wetzel + * Headers/Foundation/NSFileManager.h + * Source/NSFileManager.m + add attributesOfItemAtPath:error: + 2010-06-22 Richard Frith-Macdonald * Headers/Additions/GNUstepBase/GSVersionMacros.h: diff --git a/Headers/Foundation/NSFileManager.h b/Headers/Foundation/NSFileManager.h index 86630e011..1c269b247 100644 --- a/Headers/Foundation/NSFileManager.h +++ b/Headers/Foundation/NSFileManager.h @@ -248,6 +248,9 @@ typedef uint32_t OSType; - (NSDirectoryEnumerator*) enumeratorAtPath: (NSString*)path; - (NSDictionary*) fileAttributesAtPath: (NSString*)path traverseLink: (BOOL)flag; + +- (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error; + - (BOOL) fileExistsAtPath: (NSString*)path; - (BOOL) fileExistsAtPath: (NSString*)path isDirectory: (BOOL*)isDirectory; - (NSDictionary*) fileSystemAttributesAtPath: (NSString*)path; diff --git a/Source/NSFileManager.m b/Source/NSFileManager.m index 76445c5f2..1ecd1c44e 100644 --- a/Source/NSFileManager.m +++ b/Source/NSFileManager.m @@ -1748,6 +1748,93 @@ static NSStringEncoding defaultEncoding; return d; } +/** + * If a file (or directory etc) exists at the specified path, and can be + * queried for its attributes, this method returns a dictionary containing + * the various attributes of that file. Otherwise nil is returned.
+ * If an error occurs, error describes the problem. + * Pass NULL if you do not want error information. + *

+ * The dictionary keys for attributes are - + *

+ * + * NSFileAppendOnly + * NSNumber ... boolean + * NSFileCreationDate + * NSDate when the file was created (if supported) + * NSFileDeviceIdentifier + * NSNumber (identifies the device on which the file is stored) + * NSFileExtensionHidden + * NSNumber ... boolean + * NSFileGroupOwnerAccountName + * NSString name of the file group + * NSFileGroupOwnerAccountID + * NSNumber ID of the file group + * NSFileHFSCreatorCode + * NSNumber not used + * NSFileHFSTypeCode + * NSNumber not used + * NSFileImmutable + * NSNumber ... boolean + * NSFileModificationDate + * NSDate when the file was last modified + * NSFileOwnerAccountName + * NSString name of the file owner + * NSFileOwnerAccountID + * NSNumber ID of the file owner + * NSFilePosixPermissions + * NSNumber posix access permissions mask + * NSFileReferenceCount + * NSNumber number of links to this file + * NSFileSize + * NSNumber size of the file in bytes + * NSFileSystemFileNumber + * NSNumber the identifier for the file on the filesystem + * NSFileSystemNumber + * NSNumber the filesystem on which the file is stored + * NSFileType + * NSString the type of file + * + *

+ * The [NSDictionary] class also has a set of convenience accessor methods + * which enable you to get at file attribute information more efficiently + * than using the keys above to extract it. You should generally + * use the accessor methods where they are available. + *

+ * + * [NSDictionary-fileCreationDate] + * [NSDictionary-fileExtensionHidden] + * [NSDictionary-fileHFSCreatorCode] + * [NSDictionary-fileHFSTypeCode] + * [NSDictionary-fileIsAppendOnly] + * [NSDictionary-fileIsImmutable] + * [NSDictionary-fileSize] + * [NSDictionary-fileType] + * [NSDictionary-fileOwnerAccountName] + * [NSDictionary-fileOwnerAccountID] + * [NSDictionary-fileGroupOwnerAccountName] + * [NSDictionary-fileGroupOwnerAccountID] + * [NSDictionary-fileModificationDate] + * [NSDictionary-filePosixPermissions] + * [NSDictionary-fileSystemNumber] + * [NSDictionary-fileSystemFileNumber] + * + */ +- (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error +{ + NSDictionary *d; + + d = [GSAttrDictionaryClass attributesAt: + [self fileSystemRepresentationWithPath: path] traverseLink: NO]; + + if (error != NULL) + { + *error = [NSError _last]; + } + + return d; +} + /** * Returns a dictionary containing the filesystem attributes for the * specified path (or nil if the path is not valid).