【发布时间】:2021-04-02 14:23:42
【问题描述】:
我的文件夹中有一些文件。我正在保存“data_20201223163209.pdf”、“data_20201223171831.pdf”、“data_20201222171831.pdf”、“data_20201221171831.pdf”等文件。现在我想用“newdata”等其他字符串替换“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)
}
请帮我解决这个问题
【问题讨论】:
-
“解决这个问题” 问题是什么?未经用户同意,您不得访问那里的文件。您如何访问它们?
-
NSDocument标签是干什么用的?
标签: swift nsfilemanager