Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when trying to copy file

I'm trying to copy a temp file to another location using NSFileManager. However it's failing and complaining that one of the files does not exists.

 //Copy temp file
    NSError *error;
    BOOL exists = [fileManager fileExistsAtPath:chapterFileTemp];
    exists = [fileManager fileExistsAtPath:chapterFile];

    [fileManager copyItemAtURL:[NSURL fileURLWithPath:chapterFileTemp]
                         toURL:[NSURL fileURLWithPath:chapterFile]
                         error:&error];

    //Delete temp path
    [fileManager removeItemAtURL:[NSURL fileURLWithPath:chapterFileTemp] error:&error];

I'm getting error at copy operation

(Error Domain=NSCocoaErrorDomain Code=260 "The operation couldn’t be completed. (Cocoa error 260.)" UserInfo=0x1c5190b0 {NSFilePath=/var/mobile/Applications/57727CCD-88AD-4D84-8C78-EA8100645C9B/Documents/119/myFileTemp.temp, NSUnderlyingError=0x1c527960 "The operation couldn’t be completed. No such file or directory").

Now the first BOOL returns YES, and the second one NO. Which is expected.

What could be the reason for failure

Thanks.

like image 433
Pablo Avatar asked Oct 25 '25 09:10

Pablo


1 Answers

This is possible when the destination path is missing the directory. Make sure that the place at which you want to copy the source file is containing all required directory.

like image 62
Apurv Avatar answered Oct 26 '25 22:10

Apurv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!