title: How can I keep the new files and delete the files older than 7200 seconds only?
body: <p>How can I keep the new files (Less than 7200 seconds) and delete the older files only?</p>
  <h1>My php code:</h1>
  <pre><code>&lt;?php
  date_default_timezone_set(&quot;Europe/Amsterdam&quot;); // bepaal de tijd zone!
  // Bepaal het root path
  $site_root_path = $_SERVER['DOCUMENT_ROOT'] . '/';
  
  // Leegt de cache map en verwijderd de bestanden op basis van de leeftijd
  function verwijder_cache(){
      global $site_root_path;
      $site_cache = ($site_root_path . 'cache');
      
      // tijd in seconden dat de bestanden toegestaan zijn in de cache directory te verblijven
      $seconds_oud = 7200; // 604800 is 7 dagen, 7200 is 2 uur!
      
      // directory check-in first
      if (is_dir($site_cache)){
          $verwerk = opendir($site_cache);
          while (false !== ($tmp_site_cache_files = readdir($verwerk))){
              // We gaan nu alles verwijderen behalve index.php, .htaccess en alle sub mappen in de cache directory
              if ($tmp_site_cache_files != &quot;.&quot; &amp;&amp; $tmp_site_cache_files != &quot;..&quot; &amp;&amp; $tmp_site_cache_files != &quot;index.php&quot; &amp;&amp; $tmp_site_cache_files != &quot;.htaccess&quot;){
                  $verschil = (time() - filectime($site_cache / $tmp_site_cache_files));
                  if ($verschil &gt;= $seconds_oud){ // Testje...
                      unlink($site_cache. '/' . $tmp_site_cache_files);
                      }
                      }
                      }
                      closedir($verwerk);
                      echo 'Alle bestanden, ouder dan ' . $seconds_oud . ' seconden zijn verwijderd van de server website cache!' . &quot;\r\n&quot;;
                      }
                      // Dit zou nooit mogen gebeuren...
                      else
                          {
                          trigger_error('CACHE DIRECTORY ERROR');
                          }
                          }
                          verwijder_cache();
                          ?&gt;
  </code></pre>
  <p>I'd like to delete files from a folder with php7.
  I use the code displayed above and I'd like to keep files younger than 7200 seconds only, files over 7200 seconds should be deleted from the folder.</p>
  <p>I also want to keep index.php, .htaccess and all directories/folders in the cache folder</p>
  <p>The code does delete the files corectly and doesn't delete the files I'd like to keep but it does delete the files less than 7200 seconds as well.</p>
  <p>How can I keep the new files (Less than 7200 seconds) and delete the older files only?</p>