如何快速更改文档文件夹中的文件名

问题描述

我的文档文件夹中有一些文件。我正在保存诸如“data_20201223163209.pdf”、“data_20201223171831.pdf”、“data_20201222171831.pdf”、“data_20201221171831.pdf”等文件。现在我想用其他字符串替换“data”,比如“data”。所以我的文件应该是“newdata_20201223163209.pdf”、“newdata_20201223171831.pdf”、“newdata_20201222171831.pdf”、“newdata_20201221171831.pdf”

我的代码

do {
    let path = NSSearchPathForDirectoriesInDomains(.documentDirectory,.userDomainMask,true)[0]
    let documentDirectory = URL(fileURLWithPath: path)
    let originPath = documentDirectory.appendingPathComponent("data")
    let destinationPath = documentDirectory.appendingPathComponent("newdata")
    try FileManager.default.moveItem(at: originPath,to: destinationPath)
} catch {
    print(error)
}

请帮我解决这个问题

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)