If the *.txt files are also located in the root_compressed folder, you need to include that as well in your rm command:
exec(
'rm -rf ../root_compressed/*.php ../root_compressed/*.txt'
//.' '.$SILENT
, $out, $ret);
You can also use curly brace expansion if your server supports it:
exec(
'rm -rf ../root_compressed/*.{php,txt}'
, $out, $ret);
Note that the recursive flag (-r
) on the rm
command won't do much in this case, since you're only looking explicitly for *.php and *.txt entries. So unless your subfolders are named like that, this will not recursively delete all *.php and *.txt from every subfolder in the root_compressed folder.
I tried getting a one-liner command to do that using find
, but I couldn't get it to accept two file types in one argument. You'd have to use something like find ../root_compressed -type f -name "*.php" -delete
multiple times for each file type you want to delete.
However, it's quite easy to script it yourself using the SPL library:
$dir_iterator = new RecursiveDirectoryIterator("../root_compressed");
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $file) {
if ($file->isFile() && preg_match("~\.(php|txt)$~i", $file->getFilename())) {
unlink($file->getRealpath());
}
}