func setupFileRename(_ filePath: String) -> String {
let url = URL(fileURLWithPath: filePath)
let newPath = filePath.replacingOccurrences(of: url.lastPathComponent, with: "")
let moveToPath = newPath + currentTime() + "." + url.pathExtension
do {
try FileManager.default.moveItem(at: url, to: URL(fileURLWithPath: moveToPath))
return moveToPath
} catch {
return ""
}
}
func currentTime() -> String {
let formatter = DateFormatter()
formatter.dateFormat = "yyyyMMddHHmmss"
return formatter.string(from: Date())
}
网友评论