我正在尝试使用以下代码从我的应用程序的文档目录中删除一个文件夹:
NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
NSString *downloadFolder = [documentsPath stringByAppendingPathComponent:@"downloads"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([eraseDevice isEqualToString:@"true"])
{
if ([fileManager removeItemAtPath:downloadFolder error:NULL] == YES)
NSLog(@"downloads folder deleted");
else
NSLog(@"erase downloads failed");
}
调用时,控制台会打印downloads folder deleted
,但目录仍然存在。
有人可以告诉我上面的代码有什么问题或如何删除有问题的文件夹吗?谢谢。
-编辑以添加文档路径和下载文件夹的 NSLogs-
/Users/User/Library/Application Support/iPhone Simulator/6.0/Applications/6C785921-89B8-49C9-8BFC-06564B95C72C/Documents
/Users/User/Library/Application Support/iPhone Simulator/6.0/Applications/6C785921-89B8-49C9-8BFC-06564B95C72C/Documents/downloads