setAttributes(_:ofItemAtPath:)
Sets the attributes of the specified file or directory.
Declaration
func setAttributes(_ attributes: [FileAttributeKey : Any], ofItemAtPath path: String) throwsParameters
- attributes:
A dictionary containing as keys the attributes to set for
pathand as values the corresponding value for the attribute. You can set the following attributes: Busy, Creationdate, Extensionhidden, Groupowneraccountid, Groupowneraccountname, Hfscreatorcode, Hfstypecode, Immutable, Modificationdate, Owneraccountid, Owneraccountname, 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
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.