如何删除xxxx.app目录中的文件



我有以下代码:

NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *path1 = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"txt"];
if([fileManager fileExistsAtPath:path1]) {
    NSLog(@"-- sample file found --");

    AccessQuestionsDB *accessQuestionDataFunction = [AccessQuestionsDB new];
    idCounter = [accessQuestionDataFunction populateTheDatabase: path1 theID:0 firstTime: YES];
    [accessQuestionDataFunction release];
    [fileManager removeItemAtPath:path1 error:NULL];
    if ([fileManager fileExistsAtPath:path1]) {
        NSLog (@"Remove %@ successful", path1);
    } else {
        NSLog (@"Remove %@ failed", path1);
    }
}
else {
    NSLog(@"-- NO SAMPLE FILE! --");
}

输出:

2011-06-13 21:41:04.471 xxxx[1726:707] Remove /var/mobile/Applications/B1CC3E09-2A1D-4CD7-976D-E190A238EC79/xxxx.app/myFile.txt successful

当我运行程序时,它指示文件已删除,请参阅上面的内容,但事实并非如此。当我使用"iPhone Explorer"进行检查时,文件仍然位于"xxxx.app"目录中,我猜这是应用程序的根目录。

如果有人能告诉我如何真正删除这个文件,我会非常感激,因为我需要删除它。

您不能删除应用程序捆绑包中的文件。此外,

if ([fileManager fileExistsAtPath:path1]) {
    NSLog (@"Remove %@ successful", path1);
} else {
    NSLog (@"Remove %@ failed", path1);
}

输出"删除成功",因为您在fileExistsAtPath时输出,即未删除时输出。

在.app捆绑包签名并放置在设备上后,就不能添加或删除该捆绑包中的文件。

相关内容

最新更新