Swift 根据路径获取文件大小

        var fileSize : UInt64 = 0
         
        do {
            let attr = try FileManager.default.attributesOfItem(atPath: path)
            fileSize = attr[FileAttributeKey.size] as! UInt64
             
            let dict = attr as NSDictionary
            fileSize = dict.fileSize()
        } catch {
            print("Error: \(error)")
        }

fileSize就是文件大小

猜你喜欢

转载自blog.csdn.net/bitcser/article/details/90785528