如何删除文件夹中的所有文件,但不是文件夹本身? [英] how to delete all files in a folder, but not the folder itself?

查看:103
本文介绍了如何删除文件夹中的所有文件,但不是文件夹本身?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试删除所有文件,包括文件夹中的子目录:

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 expect is an empty folder. Could anyone please help me what did I do wrong?

真的感谢您的帮助! :)

Really thanks your help! :)

推荐答案

您应该致电 contentsOfDirectoryAtPath ,然后在它返回的所有路径上使用removeItemAtPath。

You should call contentsOfDirectoryAtPath on the directory in question, and then use removeItemAtPath on all of the paths it returns.

这篇关于如何删除文件夹中的所有文件,但不是文件夹本身?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆