07-20-2023, 12:50 PM
Edit: I found more context on this problem and asked another question
I am creating a Swift script to calculate the size of a bunch of frameworks in my app. It seems to work, but the sizes don't add up.
In finder on a specific framework, `Get Info` shows 6,801 KB
In my script, I'm using this code to get the file sizes (with different keys):
var bool: ObjCBool = false
if FileManager.default.fileExists(atPath: documentsDirectoryURL.path, isDirectory: &bool), bool.boolValue {
var folderSize = 0
FileManager.default.enumerator(at: documentsDirectoryURL, includingPropertiesForKeys: [.<key_here>], options: [])?.forEach {
folderSize += (try? ($0 as? URL)?.resourceValues(forKeys: [.<key_here>]))??.<key_here> ?? 0
}
return Int64(folderSize)
}
I get 4,133 KB with `fileAllocatedSizeKey` & `totalFileAllocatedSizeKey`
I get 4,126 KB with `fileSizeKey` & `totalFileSizeKey`
According to the [docs][1], the difference between these 4 keys has to do with metadata and the size vs allocated size. If I'm getting allocated size, why is there still 2-3 MB missing between these sizes?
PS: In this example the Finder version was bigger, but in many others the size calculated in the script is larger than the size from Finder.
I don't know what to trust!
[1]:
[To see links please register here]
I am creating a Swift script to calculate the size of a bunch of frameworks in my app. It seems to work, but the sizes don't add up.
In finder on a specific framework, `Get Info` shows 6,801 KB
In my script, I'm using this code to get the file sizes (with different keys):
var bool: ObjCBool = false
if FileManager.default.fileExists(atPath: documentsDirectoryURL.path, isDirectory: &bool), bool.boolValue {
var folderSize = 0
FileManager.default.enumerator(at: documentsDirectoryURL, includingPropertiesForKeys: [.<key_here>], options: [])?.forEach {
folderSize += (try? ($0 as? URL)?.resourceValues(forKeys: [.<key_here>]))??.<key_here> ?? 0
}
return Int64(folderSize)
}
I get 4,133 KB with `fileAllocatedSizeKey` & `totalFileAllocatedSizeKey`
I get 4,126 KB with `fileSizeKey` & `totalFileSizeKey`
According to the [docs][1], the difference between these 4 keys has to do with metadata and the size vs allocated size. If I'm getting allocated size, why is there still 2-3 MB missing between these sizes?
PS: In this example the Finder version was bigger, but in many others the size calculated in the script is larger than the size from Finder.
I don't know what to trust!
[1]:
[To see links please register here]