Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSFileManager :moveItemAtPath

Tags:

ios

NSString* path = [[NSBundle mainBundle] pathForResource:@"js" ofType:nil];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if (path != nil) {
    NSFileManager *fm = [NSFileManager defaultManager];
    NSString* move_path = [NSString stringWithFormat:@"%@",  [paths objectAtIndex:0]];
    NSError *error; 
    if ([fm moveItemAtPath:path toPath:move_path error:&error]) {
        NSLog(@"***************** success!");
    } else {
        NSLog(@"***************** fail!");
    }    }

It fails without fail.

js & move_js is not null;

path = /var/mobile/Applications/06C82222-0ABF-4009-BD58-31B799DC7C33/adhoc.app/js
move_path = /var/mobile/Applications/06C82222-0ABF-4009-BD58-31B799DC7C33/Documents
like image 435
user375364 Avatar asked Dec 10 '25 20:12

user375364


1 Answers

You're trying to move file from application bundle but you can't do so - you can't change anything in it. Instead of moving the file just copy it:

if ([fm copyItemAtPath:path toPath:move_path error:&error]) {
like image 82
Vladimir Avatar answered Dec 12 '25 10:12

Vladimir