---
title: "setAttributes(_:ofItemAtPath:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/filemanager/setattributes(_:ofitematpath:)"
---

# setAttributes(_:ofItemAtPath:)

Sets the attributes of the specified file or directory.

## Declaration

```swift
func setAttributes(_ attributes: [FileAttributeKey : Any], ofItemAtPath path: String) throws
```

## Parameters

- `attributes`: A dictionary containing as keys the attributes to set for path and as values the corresponding value for the attribute. You can set the following attributes: doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/busy, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/creationDate, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/extensionHidden, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/groupOwnerAccountID, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/groupOwnerAccountName, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/hfsCreatorCode, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/hfsTypeCode, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/immutable, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/modificationDate, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/ownerAccountID, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/ownerAccountName, doc://com.apple.foundation/documentation/Foundation/FileAttributeKey/posixPermissions. You can change single attributes or any combination of attributes; you need not specify keys for all attributes.
- `path`: The path of a file or directory.

## Discussion

Discussion As in the POSIX standard, the app either must own the file or directory or must be running as superuser for attribute changes to take effect. The method attempts to make all changes specified in attributes and ignores any rejection of an attempted modification. If the last component of the path is a symbolic link, the system traverses it. You must initialize the posixPermissions value with the code representing the POSIX file-permissions bit pattern. The system sets hfsCreatorCode and hfsTypeCode only when path specifies a file. note: In Swift, this method returns Void and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Getting and setting attributes

- [componentsToDisplay(forPath:)](foundation/filemanager/componentstodisplay(forpath:).md)
- [displayName(atPath:)](foundation/filemanager/displayname(atpath:).md)
- [attributesOfItem(atPath:)](foundation/filemanager/attributesofitem(atpath:).md)
- [attributesOfFileSystem(forPath:)](foundation/filemanager/attributesoffilesystem(forpath:).md)
