title: How to have C# program only store files younger than 7 days in temporary directory
body: <p>I have the following class which will put all files from a particular location of the device into a temporary directory:</p>
  
  <pre><code>private void GetLogs()
  {
  try
  {
      if (CurrentLogs.DoesExist())
      {
          string tmpLoc = Path.Combine(_TempPath, "CurrentLogs");
          Directory.CreateDirectory(tmpLoc);
  
          File.WriteAllText(string.Concat(tmpLoc, @"\error.txt"), CurrentLogs.GetLog("logs/error"));
          File.WriteAllText(string.Concat(tmpLoc, @"\debug.txt"), CurrentLogs.GetLog("logs/debug"));
          File.WriteAllText(string.Concat(tmpLoc, @"\debug2.txt"), CurrentLogs.GetLog("logs/debug2"));
      }
  }
  catch (Exception ex)  {
          var e = ex;
  }
  }
  </code></pre>
  
  <p>This works well however I'm finding this collects too many files and I need to only collect logs from this location that are not older than 7 days.</p>
  
  <p>I was thinking about using something similar to the following but it doesn't seem to work:</p>
  
  <pre><code>private void GetLogs()
  {
  try
  {
      if (CurrentLogs.DoesExist())
      {
          string tmpLoc = Path.Combine(_TempPath, "CurrentLogs");
          Directory.CreateDirectory(tmpLoc);
  
          DateTime FileAgeLimit = DateTime.Now.AddDays(-7);
          DateTime dt = File.GetLastWriteTime(path);
  
          foreach (var file in CurrentLogs) {
              if (dt &lt; FileAgeLimit {
                  File.WriteAllText(string.Concat(tmpLoc, @"\error.txt"), CurrentLogs.GetLog("logs/error"));
                  File.WriteAllText(string.Concat(tmpLoc, @"\debug.txt"), CurrentLogs.GetLog("logs/debug"));
                  File.WriteAllText(string.Concat(tmpLoc, @"\debug2.txt"), CurrentLogs.GetLog("logs/debug2"));
              }
          }
  
      }
      catch (Exception ex)  {
          var e = ex;
      }
  }
  }
  </code></pre>
  
  <p>Is anyone able to see the error of my ways? :)</p>