iOS 修改文件名称

2021-09-23  本文已影响0人  QianQianPeng
    private func getFilePath() -> String {
        NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first! + "/"
    }
public func changeFileName(_ newName: String,_ oldName: String) -> Bool {t
    let oldFilePath = getFilePath() + oldName
    let newPath = getFilePath() + newName
    let url = URL(fileURLWithPath: oldFilePath)
    var modifyStatus = false
    do {
        try FileManager.default.moveItem(at: url, to: URL(fileURLWithPath: newPath))
        modifyStatus = true
    } catch  {
        modifyStatus = false
    }
    return modifyStatus
}
上一篇 下一篇

猜你喜欢

热点阅读