NSFileManager: moveItemAtPath

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!");
    }    }

He is failing.

js and move_js are 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
+3
source share
1 answer

You are trying to move a file from an application package, but you cannot do this - you cannot change anything in it. Instead of moving the file, just copy it:

if ([fm copyItemAtPath:path toPath:move_path error:&error]) {
+6
source

All Articles