I would like to delete a directory if and only if it contains 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?
When you use
Directory.Delete(String)it will throw anIOExceptionwhen your specified directory is not empty.