我通过下面的方式获得一组文件的URL
let openPanel = NSOpenPanel()
openPanel.allowsMultipleSelection = true
openPanel.canChooseDirectories = false
if openPanel.runModal() == .OK {
self.openedFiles = openPanel.urls;
}
然后对其进行重命名
let fileManager = FileManager.default
for index in 0..<openedFiles.count {
let url: URL = openedFiles[index]
let newFileName = getNewFileName(url: url)
let newURL = URL(string: newFileName, relativeTo: url)!
do {
try FileManager.default.moveItem(at: url, to: newURL)
} catch let error {
dump(error)
}
}
然后会提示没有权限
couldn’t be moved because you don’t have permission to access
这里的设置已经修改为 Read/Write
谢谢
将 App Sandbox 设置为 No 可以了。