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

  • Home
  • SEARCH
  • 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 6908309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:32:49+00:00 2026-05-27T08:32:49+00:00

I can copy files from my main bundle to my Documents directory by filename

  • 0

I can copy files from my main bundle to my Documents directory by filename with the code below, but how can I copy based on wildcard? For example I have several files named myimageX.jpg (x representing a random number). I would like to loop through all of them that are contained in my main bundle and if they don’t exist in Documents, copy them.

BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];

myfileName = @"myimage322.jpg";
documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
documentsDir = [documentPaths objectAtIndex:0];
filePath = [documentsDir stringByAppendingPathComponent:myfileName];

success = [fileManager fileExistsAtPath:filePath];
if(success) return;
NSString *filePathFromApp = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:myfileName];
[fileManager copyItemAtPath:filePathFromApp toPath:filePath error:nil];

[fileManager release];
  • 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-27T08:32:49+00:00Added an answer on May 27, 2026 at 8:32 am

    The method fileExistsAtPath would be helpful. First enumerate through the contents of the bundle and check whether the same file (of the same filename) exists in the Documents.

    Here is how to do it:

    NSString *docsDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
    NSString *bundleDir = [[NSBundle mainBundle] resourcePath];
    
    NSFileManager *localFileManager=[[NSFileManager alloc] init];
    NSDirectoryEnumerator *dirEnum = [localFileManager enumeratorAtPath:bundleDir];
    
    NSString *file;
    
    while (file = [dirEnum nextObject]) {
    
        if (![[NSFileManager defaultManager] fileExistsAtPath: [docsDir stringByAppendingPathComponent:file]]) {
    
            [[NSFileManager defaultManager] copyItemAtPath:[bundleDir stringByAppendingPathComponent:file] 
                                                    toPath:[docsDir stringByAppendingPathComponent:file] error:nil];         
        }
    
    }
    
    [localFileManager release];
    

    This is a modified version of the code from NSFileManager class reference that can be found here:
    http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html

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

Sidebar

Related Questions

But how can I copy a file from one dv server to another with
with the shutil.copytree I can copy an entire directory with files and folders into
I have a windows service set to copy files from a local directory to
I want to copy file from app NSBundle to Documents directory. How ever i
.NET: How can I copy the files using Windows Copy Files dialog. I need
I'm trying to preview images and other files from the app's documents folder. I
I am trying to create a bunch of directories/subdirectories that I can copy files
I have installed openssl for developers from http://gnuwin32.sourceforge.net/packages/openssl.htm . Then, I copy the files
i have implement sqlite database in my iPhone app.i can read from db but
I am not able to copy files from my assets folder to the Sd

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.