开发者

How do I properly delete a directory only if it is empty?

I would like to delete a directory if and only if it c开发者_JAVA百科ontains no files.

I'm currently checking for 0 file system entries within the directory then deleting right away, but that leaves an edge case that I would like to avoid. Something like locking the directory seems to be the way. Most filesystems probably don't offer this feature, but maybe there is some workaround?


if directory is not empty Directory.Delete doesn't deletes it and throws IOException


When you use Directory.Delete(String) it will throw an IOException when your specified directory is not empty.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜