属性のファイルするためにいくつかの文字列値を設定し、我々はファイルスウィフトは、Appleのドキュメントによると
属性はパスのためにとに対応する値を値として設定するキーとして含む辞書の属性の多くを設定することができます属性。次の属性を設定できます。ビジー、creationDate、extensionHidden、groupOwnerAccountID、groupOwnerAccountName、hfsCreatorCode、hfsTypeCode、不変、modificationDate、ownerAccountID、ownerAccountName、posixPermissions。単一の属性または任意の属性の組み合わせを変更できます。すべての属性にキーを指定する必要はありません。
ファイルの追加パラメータを設定したいとします。パラメータは文字列です。文字列を設定できる属性は見つかりません。 は例えば、私は
try FileManager.default.setAttributes([FileAttributeKey.ownerAccountName: NSString(string: "0B2TwsHM7lBpSMU1tNXVfSEp0RGs"), FileAttributeKey.creationDate: date], ofItemAtPath: filePath.path)
を試してみました。しかし、私は鍵をロードするとき、私は唯一の.creationDateが
[__C.FileAttributeKey(_rawValue: NSFileType): NSFileTypeRegular,
__C.FileAttributeKey(_rawValue: NSFilePosixPermissions): 420,
__C.FileAttributeKey(_rawValue: NSFileSystemNumber): 16777220,
__C.FileAttributeKey(_rawValue: NSFileReferenceCount): 1,
__C.FileAttributeKey(_rawValue: NSFileGroupOwnerAccountName): staff,
__C.FileAttributeKey(_rawValue: NSFileSystemFileNumber): 8423614,
__C.FileAttributeKey(_rawValue: NSFileGroupOwnerAccountID): 20,
__C.FileAttributeKey(_rawValue: NSFileModificationDate): 2017-08-16 06:03:57 +0000,
__C.FileAttributeKey(_rawValue: NSFileCreationDate): 1970-01-01 00:33:20 +0000,
__C.FileAttributeKey(_rawValue: NSFileSize): 9795,
__C.FileAttributeKey(_rawValue: NSFileExtensionHidden): 0,
__C.FileAttributeKey(_rawValue: NSFileOwnerAccountID): 501]
を変更します
let keys = try FileManager.default.attributesOfItem(atPath: filePath.path)
print(keys)
は、私がFileAttributeに文字列値を設定することができます任意の方法はあります?
権限の問題?ファイル(およびルート)の所有者だけが所有者属性を変更できます。 –
いいえ、私はrootユーザーのアカウント名を使用しようとしましたが、動作しませんでした。 – Alex