开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜