I love file systems. You can do all sorts of neat tricks, sharing state based on file existence and naming. If it ends in ".tmp", it's not done yet. If it ends in "_hostname", that's who's handling it. I wish I could remember who said that "back in the day, they had transaction safe databases: we called them file systems."

When doing tricks like these, it is important to have four operations: touch, stat, mv, and rm. Recently, Anne found code written by someone that just didn't think the standard functions in C# were up to snuff. Here's an advanced version of FileExists for your perusal.

 

  private bool FileExists(string strPath)
  {
      try
      {
          File.WriteAllText(strPath, "narf");
          return true;
      }
      catch (Exception ex) {/* do nothing */}

      return false;
  }

 

The best part is that raw user input was being fed into FileExists. So if you ever wanted to know if C:\Windows\System32\ntoskrnl.exe exists...

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!