I'm curious if the method, Directory.GetLastWriteTime puts a lock on the directory in question momentarily?
We're seeing the error, 'The directory is not empty' when trying to do a Directory.Delete(filePath, true) on some directory after calculating if it's old or not. This does not happen every time.
After further research, I understand that Directory.Delete(filePath, true) will throw this error when a sub-directory of the directory to be deleted is open in File Explorer (Cannot delete directory with Directory.Delete(path, true)). I am able to reproduce this behavior by opening one of the sub-directories in Windows Explorer and then trying to do a Directory.Delete(filePath, true).
Which leads me to my question - we are not opening these directories through code anywhere, and the only other thing we do with the directory is GetLastWriteTime. Could this method be causing the same behavior?