Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 402037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:05:19+00:00 2026-05-12T17:05:19+00:00

I am trying to copy an mp3 file from my Resources folder to a

  • 0

I am trying to copy an mp3 file from my Resources folder to a folder inside “Documents” folder of the app. On the simulator this works fine. But when I run it on a device, copying the files gives me this error

Operation could not be completed. (Cocoa error 513.)

The source and destinations paths are fine but I still cannot copy the file. Any ideas? Where can I find out what the cocoa error code 513 means?

Thanks.

Here’s the relevant source code

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *folderPath = [documentsDirectory stringByAppendingPathComponent:@"Files"];

    NSString *insPath = [NSString stringWithFormat:@"%@.mp3", fileName];
    NSString *srcPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:insPath];
    NSString *destPath = [folderPath stringByAppendingPathComponent:insPath];
    NSLog(@"Src: %@, Dest: %@", srcPath, destPath);

    NSError *err;
    [fileManager moveItemAtPath:srcPath toPath:destPath error:&err];

    NSLog(@"Err desc-%@", [err localizedDescription]);
    NSLog(@"Err reason-%@", [err localizedFailureReason]);

Before making a call to moveItemAtPath, I am also creating the directory “Files” and it returns a YES.

Here’s the log results

Src: /var/mobile/Applications/512D7565-7EF7-4C13-A015-19EEC3F3B465/MyApp.app/MyFile.mp3, Dest: /var/mobile/Applications/512D7565-7EF7-4C13-A015-19EEC3F3B465/Documents/Files/MyFile.mp3

Err desc-Operation could not be completed. (Cocoa error 513.)
Err reason-(null)

A question

Is there a limit to the file size when copying data from resources to Documents folder? The file I am trying to copy is about 5MB. Could that be a reason?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:05:19+00:00Added an answer on May 12, 2026 at 5:05 pm

    EDIT:

    Just figured out an even simpler solution. Instead of
    moveItemAtPath:toPath:error:, just use copyItemAtPath:toPath:error: … since we truly want to copy the file from the mainBundle and not move it. I should have thought of that sooner!

    E.g.

    [[NSFileManager defaultManager] copyItemAtPath:mainBundleFilePath 
                                            toPath:destPath 
                                             error:&err]
    

    See my previous comments below about why this works.


    I believe I have the answer to this question. I can say for sure that the issue is not the destination file path.

    I was getting the same Cocoa error 513 (NSFileWriteNoPermissionError) with pretty much the exact same code:

    [[NSFileManager defaultManager] moveItemAtPath:mainBundleFilePath 
                                            toPath:destPath 
                                             error:&err]
    

    The problem appears to be that the file, coming from the mainBundle, doesn’t have suitable permissions to be moved to another place. I’m not sure if this command, if executed, would actually move the file from the mainBundle or just copy it…but either way, the file manager doesn’t seem to like the idea.

    The solution is simple: just read the mainBundle file into an NSData object and then write the NSData to a new file. Note the destination file path is the same in both examples, which shows us that lostInTransit is correct in saying that his file path is OK.

    For this example, then, the following code will work and not throw an error:

    NSData *mainBundleFile = [NSData dataWithContentsOfFile:mainBundleFilePath];
    [[NSFileManager defaultManager] createFileAtPath:destPath 
                                            contents:mainBundleFile 
                                          attributes:nil];
    

    BTW, in my own code, instead of passing a nil for attributes:, I set up an NSDictionary with a NSFileModificationDate attribute. I also wrapped the createFileAtPath:contents:attributes in an error handing if-statement. In other words,

    if (![[NSFileManager defaultManager] createFileAtPath:destPath 
                                                 contents:mainBundleFile 
                                               attributes:myAttributes]) { 
     // handle error as necessary, etc...
    

    }

    It took me a while to figure all of this out, so hopefully this solution will be helpful to others.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying copy a single file from the Plugin directory inside of my Wordpress
I am trying to copy a file from my remote server to my local.
I am trying to copy a file from a child directory of my root
I am trying to copy part of a .txt file from the line number
I'm trying to copy files from a local pc to a server with file.copy.
I am trying to copy values directly from one mysql table to another... but
I'm trying to copy information from an iframe to my document, I wrote this
I'm trying to copy file to network path like '\\serverA\destenation\file', but fail with Unauthorized
So I am trying to copy a file to a new location this way:
I'm trying to copy both an image from a file and text from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.