1哑了、拷貝到目標(biāo)目錄的時(shí)候狂鞋,如果文件已經(jīng)存在則會(huì)直接失敗
2娇哆、目標(biāo)目錄必須是文件?
貼一段別人寫 文章
今天我用NSFileManager 文件拷貝函數(shù)copyItemAtPath:toPath:error:拷貝文件的時(shí)候嚎卫,一直出現(xiàn)一下錯(cuò)誤:
Error Domain=NSPOSIXErrorDomain Code=17 “The operation couldn’t be completed. File exists” UserInfo=0x9d37050 {NSUserStringVariant=Copy, NSFilePath=/Users/kimziv/Library/Application Support/iPhone Simulator/4.2/Applications/0110275A-4939-452E-BA34-CADBB63F2042/Documents/resources/ppt/media/image1.jpeg, NSDestinationFilePath=/Users/kimziv/Library/Application Support/iPhone Simulator/4.2/Applications/0110275A-4939-452E-BA34-CADBB63F2042/Documents}
后來仔細(xì)看官方文檔發(fā)現(xiàn),我是該函數(shù)的第二個(gè)參數(shù)dstPath我用錯(cuò)了迈套,要以文件名結(jié)尾捐祠。
Discussion
If srcPath is a file, the method creates a file at dstPath that holds the exact contents of the original file (this includes BSD special files). If srcPath is a directory, the method creates a new directory at dstPath and recursively populates it with duplicates of the files and directories contained in srcPath, preserving all links. The file specified in srcPath must exist, while dstPath must not exist prior to the operation.When a file is being copied, the destination path must end in a filename—there is no implicit adoption of the source filename.?Symbolic links are not traversed but are themselves copied. File or directory attributes—that is, metadata such as owner and group numbers, file permissions, and modification date—are also copied.