Documents ディレクトリに含まれるすべてのファイルとディレクトリを削除したいと考えています。
[fileManager removeItemAtPath:documentsDirectoryPath error:nil] メソッドを使用すると、ドキュメント ディレクトリも削除されると思います。
ディレクトリの内容のみを削除し、空のディレクトリをそこに残す方法はありますか?
Documents ディレクトリに含まれるすべてのファイルとディレクトリを削除したいと考えています。
[fileManager removeItemAtPath:documentsDirectoryPath error:nil] メソッドを使用すると、ドキュメント ディレクトリも削除されると思います。
ディレクトリの内容のみを削除し、空のディレクトリをそこに残す方法はありますか?
これを試して:
NSString *folderPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSError *error = nil;
for (NSString *file in [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folderPath error:&error]) {
[[NSFileManager defaultManager] removeItemAtPath:[folderPath stringByAppendingPathComponent:file] error:&error];
}