Copy plist into the Documents

Discussion in 'iOS Programming' started by Sergio10, Sep 29, 2009.

  1. Sergio10 macrumors regular

    Joined:
    Oct 3, 2007
    #1
    Hi,

    I can't copy plist into the Documents folder.
    Here is a code I developed:
    PHP:
        NSBundle *bundle = [NSBundle mainBundle];
        
    NSError *error nil;
        
    NSString *userSettingsPath = [bundle pathForResource:USER_SETTINGS_PLIST_NAME ofType:@"plist"];
        
        
    NSFileManager *fileManager = [NSFileManager defaultManager];

        
    // get "Documents" folder
        
    NSArray *searchPaths NSSearchPathForDirectoriesInDomains(NSDocumentDirectoryNSUserDomainMaskYES);
        
    NSString *documentsDirectoryPath = [searchPaths objectAtIndex:0];
        
        [
    fileManager copyItemAtPath:userSettingsPath toPath:documentsDirectoryPath error:&error];
    Could you please find the issue?

    Thanks
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You are trying to copy the plist to the wrong path: you need to append the name of the file (in the target folder) to the folder itself.

    So lets say your plist is called settings.plist. You are doing something like (as a Unix command)
    Code:
    cp /path/to/my/bundle/Resources/Settings.plist /path/to/docs/folder
    
    Whereas you need

    Code:
    cp /path/to/my/bundle/Resources/Settings.plist /path/to/docs/folder/Settings.plist
    
     

Share This Page