"Display help.", 'options|o' => " all: All files, [directory_name]: Files in this directory", ) ); $opts->parse(); } catch (Zend_Console_Getopt_Exception $e) { echo $e->getUsageMessage(); exit; } //Usage if(count($opts->getOptions())==0 || isset($opts->help)) { echo "Delete temporary files"; echo "\n\n"; echo $opts->getUsageMessage(); echo "\n"; exit; } $c = new Zend_Config($application->getOptions()); define('PATH_TEMPFILE', realpath(dirname(__FILE__).'/../cache')); //Liste des Repertoires $tempDirs = array( 'cache' => array( 'path' => 'cache', 'files' => array('*.tpl', '*.xml') ), 'files' => array( 'path' => 'files', 'files' => array('*.pdf', '*.jpeg', '*.jpg', '*.csv', '*.xls','*.xml') ), 'pages' => array( 'path' => 'pages', 'files' => array('*.html') ), 'imgcache' => array( 'path' => 'pages/imgcache', 'files' => array('*.png', '*.gif') ), 'sessions' => array( 'path' => 'sessions', 'files' => array('sess_*') ), ); /** * Suppression des fichiers dans un repertoire * @param string $path * @param string $filePattern */ function removeFile($path, $filePattern) { $dir = PATH_TEMPFILE.DIRECTORY_SEPARATOR.$path; if (is_dir($dir)) { if (stristr(PHP_OS, 'WIN')) { $cmd = 'del '.$dir.DIRECTORY_SEPARATOR.$filePattern; } else { /** * To avoid too args error from rm command */ $cmd = 'find '.$dir.'/ -name "'.$filePattern.'" -exec rm {} \;'; } return shell_exec($cmd); } return false; } function removePatternInDir($path, $tabPattern) { foreach($tabPattern as $pattern) { echo "Suppression fichiers ".$path." : "; $result = removeFile($path, $pattern); if ($result === false){ echo "Erreur"; } else { echo $result; } echo "\n"; } } foreach($tempDirs as $dir => $options) { if ($opts->options == 'all') { removePatternInDir($options['path'], $options['files']); } elseif ($opts->options == $dir) { removePatternInDir($options['path'], $options['files']); break; } }