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 8629461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:48:46+00:00 2026-06-12T08:48:46+00:00

I’d like to make a folder which has a file in MyApp.app/Document folder by

  • 0

I’d like to make a folder which has a file in MyApp.app/Document folder by using NSFileManager. (MyApp is my custom app.)

So, I copied IMG_0525.jpg (For test) to project’s folder.

And then trying to copy it from project’s folder to MyApp.app/Document folder.

But I have no idea how to specify the path name. (source and destination path)

Would you let me know how?

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [self generateTableContents];

}


- (void)generateTableContents {

    NSFileManager * fileManager = [NSFileManager defaultManager];
    NSArray *appsDirectory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentPath = [appsDirectory objectAtIndex:0];
    NSLog(@"documentPath : %@", documentPath);

    [fileManager changeCurrentDirectoryPath:documentPath];
    [fileManager createDirectoryAtPath:@"user_List1" withIntermediateDirectories:YES attributes:nil error:nil];

    // I'm trying to copy IMG_0525.jpg to MyApp.app/Document/user_List1 folder.
    [fileManager copyItemAtPath:<#(NSString *)srcPath#> toPath:<#(NSString *)dstPath#> error:<#(NSError * *)error#>];


}

enter image description here

  • 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-06-12T08:48:47+00:00Added an answer on June 12, 2026 at 8:48 am
    • Your code for getting this documents directory using NSSearchPathForDirectoriesInDomains is correct, but note that this will not point into “MyApp.app/Documents”. In fact, you can’t modify the application’s bundle content at runtime (btw it would violate the code signature of the bundle if you modify it), but you can copy files in the application’s sandbox (which is outside of the “MyApp.app” bundle), and that’s the path to this application’s sandbox’s Document folder that your call to NSSearchPathForDirectoriesInDomains will return

    • That being said, you then now have the destination folder for your file, so that is the toPath: parameter of -copyItemAtPath:toPath:error: method. The only missing part is the source path that points to the resource in your bundle (to point to the image file you added in your Xcode project once it is compiled in the bundle).

    To obtain this source path, use the -[NSBundle pathForResource:ofType:] method. This is very simple to use:

    NSString* sourcePath = [[NSBundle mainBundle] pathForResource:@"IMG_0525" ofType:"jpg"];
    
    • The last error: parameter can be NULL, or a pointer to an NSError* object if you want to retrieve the error in case the -copyItemAtPath:toPath:error: method failed. For that parameter, simply create an NSError* error; variable before your call, and pass &error to this third parameter of -copyItemAtPath:toPath:error:.

    So the complete call will look like this:

    NSError* error; // to hold the error details if things go wrong
    NSString* sourcePath = [[NSBundle mainBundle] pathForResource:@"IMG_0525" ofType:"jpg"];
    
    BOOL ok = [fileManager copyItemAtPath:sourcePath toPath: documentPath error:&error];
    if (ok) {
      NSLog(@"Copy complete!");
    } else {
      NSLog(@"Error while trying to copy image to the application's sandbox: %@", error);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.