how to delete all files in a folder, but not the folder itself?
I try to delete all files including subdirectories in a folder:
NSFileManager *deleteMgr = [NSFileManager defaultManager];
NSString *path = @"~/test/";
[deleteMgr removeItemAtPath:path error:&error];
And it deletes everything including the folder itself. But what I expec开发者_开发知识库t is an empty folder. Could anyone please help me what did I do wrong?
Really thanks your help! :)
You should call contentsOfDirectoryAtPath on the directory in question, and then use removeItemAtPath on all of the paths it returns.
精彩评论