LoginSignup
1
1

More than 1 year has passed since last update.

Swift ファイル情報の備忘録

Posted at

Swiftでファイルサイズを取得

FileManagerのattributesOfItemを使って、ファイルサイズを取得することができます。
NSDictionaryに型をキャストすることによって、用意された関数を使用することができます。
Apple attributesOfItem

使い方

import Foundation
let fileManager = FileManager.default
guard let attribute = try? fileManager.attributesOfItem(atPath: "パス") as NSDictionary else { return }
print(attribute.fileSize())

Swiftでファイル作成日を取得

print(attribute.fileCreationDate())

Swiftでファイル更新日を取得

print(attribute.fileModificationDate())

Swiftでファイル所有者のアカウントを取得

print(attribute.fileOwnerAccountName())
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1