开发者

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

开发者 https://www.devze.com 2023-03-27 05:01 出处:网络
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

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

精彩评论

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