Do what you want and code for failure
Credit to JaredPar MSFT for this. The best pattern to use with dealing with the file system is "Do the operation you want, then deal with the consequence of failure in the form of exceptions"
i.e. Don’t do this: if (File.Exists(path)) { ... } because the file could be deleted between the "Exists" check and the use of the file.
Instead, do this:
static string ReadTextOrEmpty(string path) { try { return File.ReadAllText(path); } catch (DirectoryNotFoundException) { return String.Empty; } catch (FileNotFoundException) { return String.Empty; } }
Source article blogs.msdn.microsoft.com/jaredpar/2009/12/10/the-file-system-is-unpredictable/
Additional thanks to Raymond Chen, I found this on The Old New Thing












