NSFileManager不删除存在的文件

Dev*_*ang 13 iphone nsfilemanager ios

我在使用NSFileManager功能时遇到了一些问题.这在Simulator和iPhone设备(iOS 5.1)上都会发生.

基本上,我有一堆文件存储在我创建的文档中.现在我正在尝试将文件(存储在路径中)移动到具有其他名称的同一目录,以检查删除是否有效.

if ([[NSFileManager defaultManager] isDeletableFileAtPath:path]) {
BOOL success = [[NSFileManager defaultManager] moveItemAtPath:path toPath:[path            stringByAppendingString:@".deleted"] error:&error];
if (!success) {
        NSLog(@"Error removing file at path: %@", error.localizedDescription);
    }
}
Run Code Online (Sandbox Code Playgroud)

这个输出是pathpath .deleted的文件.我最终只是想使用removeItemAtPath删除该文件,但这不起作用.它返回成功,但如果我在文件目录中看到它,即使在一小时后我仍然能看到它.

cnu*_*cnu 37

如果你想删除你应该使用一个文件removeItemAtPath:myPath error:NULL一样

NSError *error;
if ([[NSFileManager defaultManager] isDeletableFileAtPath:path]) {
    BOOL success = [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
    if (!success) {
        NSLog(@"Error removing file at path: %@", error.localizedDescription);
    }
}
Run Code Online (Sandbox Code Playgroud)