我正在使用 NSDirectoryEnumerator 清除我的应用程序的 Documents 文件夹。它主要是有效的,除了由于某种我无法理解的原因,它留下了 1 个文件。这是我的代码:
NSDirectoryEnumerator * enumerator = [fileMan enumeratorAtURL:[NSURL fileURLWithPath:docsFolder()] includingPropertiesForKeys:nil options:NSDirectoryEnumerationSkipsSubdirectoryDescendants errorHandler:^BOOL(NSURL *url, NSError *error) {
NSLog(@"%@,%@",url,error);
return YES;
}];
for (NSURL * fileURL in enumerator) {
BOOL removed = [fileMan removeItemAtURL:fileURL error:nil];
NSLog(@"Removed %@:%d",fileURL.path,removed);
}
上面代码中的docsFolder()
调用是一个函数,它简单地返回应用程序的文档文件夹,使用NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)
. 我已经在错误处理程序中设置了断点并登录,它永远不会命中。我那里有很多文件,它们都被删除了。除了,总是有一个文件,总是同一个文件,被遗忘了。这是在 iOS 8.1 的模拟器中。即使由于某种原因文件被锁定(或其他任何原因)错误处理程序应该被调用,所以我对正在发生的事情感到茫然。
是否与 Documents 文件夹中的所有文件都是指向单独文件夹中文件的“硬”链接这一事实有关?什么会导致硬链接无法...取消链接?
任何人都知道为什么会发生这种情况?