我想复制一个包含几个文件夹的文件夹,这个文件夹包含几个文件。如果此文件夹存在,我想将它们保留在内部,并覆盖文件(如果存在)。如果文件不存在,则只需自然添加。
_ = try FileManager.default.replaceItemAt(previousItemUrl, withItemAt: currentItemUrl)
例如:
设备上存在的文件:
APP/XXX/a.txt
APP/XXX/b.txt
APP/XXX/c.txt
APP/YYY/d.txt
APP/ZZZ/e.txt
APP/ZZZ/f.txt
要复制的文件:
APP/XXX/c.txt //Will override
APP/YYY/g.txt //new file added
APP/ZZZ/h.txt //new file added
APP/AAA //new folder added
我是否必须创建自己的递归函数,或者该函数是否已经存在?
提前致谢。
我们可以使用下面的本机方法。它将源复制到目标。
func copyItem(atPath srcPath: String,
toPath dstPath: String) throws
我们还可以通过实现下面提到的其他委托方法来控制覆盖用例。
optional func fileManager(_ fileManager: FileManager,
shouldCopyItemAt srcURL: URL,
to dstURL: URL) -> Bool
你可以在Apple document找到所有这些细节