--- cleaner.module	2009-09-04 11:49:12.000000000 -0700
+++ cleaner.module	2009-09-16 23:51:28.000000000 -0700
@@ -131,6 +131,22 @@ function cleaner_cleaner_settings() {
     '#description' => t('The sessions table can quickly become full with old, abandoned sessions. This will delete all sessions older than @interval (as set by your site administrator). There are currently @count such sessions.', 
       array('@interval' => format_interval($lifetime), '@count' => $count)),
     );
+    
+  $form['cleaner_clean_cssdir'] = array(
+    '#type' => 'radios',
+    '#options' => $yesno,
+    '#title' => t('Clean up CSS files'),
+    '#default_value' => variable_get('cleaner_clean_cssdir', 0),
+    '#description' => t('The css directory can become full with stale and outdated cache files.  This will delete all cache files but the latest.'),
+    );
+    
+  $form['cleaner_clean_jsdir'] = array(
+    '#type' => 'radios',
+    '#options' => $yesno,
+    '#title' => t('Clean up JS files'),
+    '#default_value' => variable_get('cleaner_clean_jsdir', 0),
+    '#description' => t('The js directory can become full with stale and outdated cache files.  This will delete all cache files but the latest.'),
+    );
 
   $ret['cleaner'] = $form;
 
@@ -145,6 +161,28 @@ function cleaner_cron() {
 }
 
 /**
+ * Deletes all cache files in a specified subdirectory of the Drupal files directory.
+ *
+ * @param $ext: the file extension of the file type, can be css or js
+ * @param $seconds: number of seconds old to delete down to, defaulted to 3600 (1 hour)
+ */
+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++;
+    }
+  }
+  watchdog('Cleaner', 'Deleted @count cached @type files.', array('@count' => $count, '@type' => $ext));
+}
+
+/**
  * Implementation of hook_cleaner_run().
  */
 function cleaner_cleaner_run() {
@@ -172,4 +210,14 @@ function cleaner_cleaner_run() {
     $count = db_affected_rows();
     watchdog('Cleaner', 'Cleared @count sessions.', array('@count' => $count));
   }
+  
+  if (variable_get('cleaner_clean_cssdir', FALSE)) {
+    // Delete css files older than 1 hour
+    cleaner_delete_files('css');
+  }
+  
+  if (variable_get('cleaner_clean_jsdir', FALSE)) {
+    // Delete js files older than 1 hour
+    cleaner_delete_files('js');
+  }
 }
