Instance Method


Returns the attributes of the item at a given path.


- (NSDictionary<NSFileAttributeKey, id> *)attributesOfItemAtPath:(NSString *)path error:(NSError * _Nullable *)error;



The path of a file or directory.


On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information. You may specify nil for this parameter if you do not want the error information.

Return Value

An NSDictionary object that describes the attributes (file, directory, symlink, and so on) of the file specified by path, or nil if an error occurred. The keys in the dictionary are described in File Attribute Keys.


If the item at the path is a symbolic link—that is, the value of the NSFileType key in the attributes dictionary is NSFileTypeSymbolicLink—you can use the destinationOfSymbolicLinkAtPath:error: method to retrieve the path of the item pointed to by the link. You can also use the stringByResolvingSymlinksInPath method of NSString to resolve links in the path before retrieving the item’s attributes.

As a convenience, NSDictionary provides a set of methods (declared as a category on NSDictionary) for quickly and efficiently obtaining attribute information from the returned dictionary: fileGroupOwnerAccountName, fileModificationDate, fileOwnerAccountName, filePosixPermissions, fileSize, fileSystemFileNumber, fileSystemNumber, and fileType.


See Also

Getting and Setting Attributes

- componentsToDisplayForPath:

Returns an array of strings representing the user-visible components of a given path.

- displayNameAtPath:

Returns the display name of the file or directory at a specified path.

- attributesOfFileSystemForPath:error:

Returns a dictionary that describes the attributes of the mounted file system on which a given path resides.

- setAttributes:ofItemAtPath:error:

Sets the attributes of the specified file or directory.