Caps-iOS/Caps/Extensions/FileManager+Extensions.swift
2022-06-21 19:38:51 +02:00

27 lines
753 B
Swift

import Foundation
extension FileManager {
var documentDirectory: URL {
try! url(
for: .documentDirectory,
in: .userDomainMask,
appropriateFor: nil, create: true)
}
private func fileSizeEnumerator(at directory: URL) -> DirectoryEnumerator? {
enumerator(at: directory,
includingPropertiesForKeys: [.totalFileAllocatedSizeKey, .fileAllocatedSizeKey],
options: []) { (_, error) -> Bool in
print(error)
return false
}
}
func directorySize(_ directory: URL) -> Int {
return fileSizeEnumerator(at: directory)?
.compactMap { $0 as? URL }
.reduce(0) { $0 + $1.fileSize } ?? 0
}
}