NSFileManager removeItemAtPath不会删除文件

时间:2014-09-15 15:28:08

标签: ios nsfilemanager

所以,我搜索了网络和stackoverflow,检查了上面提到的这个文本框中的线程尽可能已经问过问题,但答案或提示无法帮助我,因为最初的代码没问题,并且没有任何问题它,它不应该,因为它不是那么难。但由于某种原因,我无法删除以前创建的文件。代码:

NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, true);
NSString *dbFile = [[NSString alloc] initWithString:[dirPaths[0] stringByAppendingPathComponent:@"database.db"]];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
BOOL fileExists = [fileManager fileExistsAtPath:dbFile];
NSLog(@"Path to file: %@", dbFile);
NSLog(@"File exists: %d", fileExists);
NSLog(@"Is deletable file at path: %d", [fileManager isDeletableFileAtPath:dbFile]);
if (fileExists) {
    BOOL success = [fileManager removeItemAtPath:dbFile error:&error];
    if (!success) { NSLog(@"Error: %@", [error localizedDescription]); }
    else { NSLog(@"probably deleted the file!"); }
}

输出:

2014-09-15 17:29:25.058 test[13862:60b] Path to file: /var/mobile/Applications/BB708129-C504-4E84-9C08-DF4ACE1369DC/Documents/database.db
2014-09-15 17:29:25.060 test[13862:60b] File exists: 1
2014-09-15 17:29:25.061 test[13862:60b] Is deletable file at path: 1
2014-09-15 17:29:25.063 test[13862:60b] probably deleted the file!

但每次我运行代码它都说文件存在并且不会被删除。我错过了什么吗?

0 个答案:

没有答案
相关问题