我有一些文件位于我的文档文件夹中。我将这些文件命名为 "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
标签是用来做什么的? - El Tomato