Swiftでファイルのサイズや更新日時の取得方法を紹介します。
FileManager
のattributesOfItemAtPath
メソッドを使用することで簡単に取得することが出来ます。
let path = "ファイルのパス"
do {
let attributes = try FileManager().attributesOfItem(atPath: path)
print(attributes[.size]!)
print(attributes[.modificationDate]!)
} catch {
print("エラー")
}
ファイルサイズはバイトで取得されます、キロバイト表示にしたい場合などは1024で割ってあげる必要があります。
https://developer.apple.com/documentation/foundation/nsfilemanager/1410452-attributesofitematpath