开发者

NSFileManager :moveItemAtPath

开发者 https://www.devze.com 2023-03-12 18:34 出处:网络
NSString* path = [[NSBundle mainBundle] pathForResource:@\"js\" ofType:nil]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
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 n开发者_StackOverflow中文版ull;

path = /var/mobile/Applications/06C82222-0ABF-4009-BD58-31B799DC7C33/adhoc.app/js
move_path = /var/mobile/Applications/06C82222-0ABF-4009-BD58-31B799DC7C33/Documents


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]) {
0

精彩评论

暂无评论...
验证码 换一张
取 消