How To Get Directory Size With Swift On OS X

前端 未结 5 1301
孤独总比滥情好
孤独总比滥情好 2020-12-15 13:04

I am trying to get the size of a directory, as well as it\'s content on OS X using Swift. So far, I have only been able to get the size of the directory itself, with none of

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-15 13:12

    Swift 3 version

    private func sizeToPrettyString(size: UInt64) -> String {
    
        let byteCountFormatter = ByteCountFormatter()
        byteCountFormatter.allowedUnits = .useMB
        byteCountFormatter.countStyle = .file
        let folderSizeToDisplay = byteCountFormatter.string(fromByteCount: Int64(size))
    
        return folderSizeToDisplay
    
    }
    

提交回复
热议问题