部分需求修改
This commit is contained in:
62
Pods/DDUtilsSwiftKit_Private/DDUtilsSwiftKit_Private/Classes/FileManager/DDFileManager.swift
generated
Normal file
62
Pods/DDUtilsSwiftKit_Private/DDUtilsSwiftKit_Private/Classes/FileManager/DDFileManager.swift
generated
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// DDFileManager.swift
|
||||
// DDUtilsSwiftKit_Private
|
||||
// Created by DDIsFriend on 2023/10/10.
|
||||
|
||||
|
||||
import Foundation
|
||||
|
||||
public let DDFM = DDFileManager.default
|
||||
|
||||
open class DDFileManager {
|
||||
public static let `default` = DDFileManager()
|
||||
|
||||
public func calculateFile(filePath:String) -> Float {
|
||||
/// 取出文件夹下所有文件数组
|
||||
let fileArr = FileManager.default.subpaths(atPath: filePath)
|
||||
|
||||
var size: Float = 0
|
||||
|
||||
for file in fileArr!
|
||||
{
|
||||
/// 把文件名拼接到路径中
|
||||
let path = filePath.appending("/\(file)")
|
||||
|
||||
/// 取出文件属性
|
||||
let floder = try! FileManager.default.attributesOfItem(atPath: path)
|
||||
/// 用元组取出文件大小属性
|
||||
for (key, value) in floder
|
||||
{
|
||||
/// 累加文件大小
|
||||
if key == FileAttributeKey.size
|
||||
{
|
||||
size += (value as AnyObject).floatValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return size / 1024 / 1024
|
||||
}
|
||||
|
||||
public func clearFile(filePath:String) {
|
||||
// 取出文件夹下所有文件数组
|
||||
let fileArr = FileManager.default.subpaths(atPath: filePath)
|
||||
|
||||
// 遍历删除
|
||||
for file in fileArr!
|
||||
{
|
||||
let path = filePath.appending("/\(file)")
|
||||
if FileManager.default.fileExists(atPath: path)
|
||||
{
|
||||
do
|
||||
{
|
||||
try FileManager.default.removeItem(atPath: path)
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user