Contents

attributesOfItem(atPath:)

Returns the attributes of the item at a given path.

Declaration

func attributesOfItem(atPath path: String) throws -> [FileAttributeKey : Any]

Parameters

  • path:

    The path of a file or directory.

Return Value

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

Discussion

If the item at the path is a symbolic link—that is, the value of the type key in the attributes dictionary is typeSymbolicLink—you can use the destinationOfSymbolicLink(atPath:) method to retrieve the path of the item pointed to by the link. You can also use the resolvingSymlinksInPath 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().

Discussion

See Also

Getting and setting attributes