You are here

function cleaner_delete_files in Cleaner 6

Deletes all cache files in a specified subdirectory of the Drupal files directory.

Parameters

$ext: the file extension of the file type, can be css or js:

$seconds: number of seconds old to delete down to, defaulted to 3600 (1 hour):

1 call to cleaner_delete_files()
cleaner_cleaner_run in ./cleaner.module
Implementation of hook_cleaner_run().

File

./cleaner.module, line 199
Allows the admin to set a schedule for clearing caches and other stuff.

Code

function cleaner_delete_files($ext, $seconds = 3600) {
  $count = 0;
  $dir = file_directory_path() . "/{$ext}";
  $mask = $ext . '_(.*)\\.' . $ext . '$';
  if (file_check_directory($dir) != 1) {
    return;
  }
  $files = file_scan_directory($dir, $mask);
  foreach ($files as $obj) {
    $filepath = $obj->filename;
    if (filemtime($filepath) < time() - $seconds) {
      file_delete($filepath);
      $count++;
    }
  }
  if ($count) {
    watchdog('Cleaner', 'Deleted @count cached @type files.', array(
      '@count' => $count,
      '@type' => $ext,
    ), WATCHDOG_NOTICE, url('admin/settings/cleaner'));
  }
}