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.
精彩评论