Last active
September 24, 2018 02:36
-
-
Save jayz5/1b0da03a06ae14a8d2983387fc5adbe6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension FileManager { | |
func checkFileSizes(in folderURL: URL) { | |
do { | |
let resourceKeys: [URLResourceKey] = | |
[.fileSizeKey, .fileAllocatedSizeKey, .isRegularFileKey, .isDirectoryKey] | |
for url in try contentsOfDirectory(at: folderURL, | |
includingPropertiesForKeys: resourceKeys, | |
options: []) | |
{ | |
let resourceValues = try url.resourceValues(forKeys: Set(resourceKeys)) | |
print("\n\(url.lastPathComponent) resources: \n") | |
print(" \(URLResourceKey.fileSizeKey.rawValue): \(resourceValues.fileSize ?? 0)") | |
print(" \(URLResourceKey.fileAllocatedSizeKey.rawValue): \(resourceValues.fileAllocatedSize ?? 0)") | |
if let isDirectory = resourceValues.isDirectory, isDirectory { | |
checkFileSizes(in: url) | |
} | |
} | |
} catch { | |
print("check file size errors: \(error)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment