[thelist] PHP Questions
Steve Webster
steve at netbreed.co.uk
Mon Sep 30 07:31:07 CDT 2002
Tony Crockford wrote:
>Hi
>
>Q1, is there a better list to ask PHP questions on?
>
>
Not really a list, but you could always try the comp.lang.php newsgroup.
>Q2,
>
>Anyone got any tips, tutorials or code snippets that would allow me to
>automatically delete *.htm files from all sub-directories off a given
>directory?
>
>
You want a recursive function to search through all directories from a
base directory and remove all files that match a cartain pattern. Kinda
like this...
function deleteFiles($filter, $sDirectory) {
$cDirectory = includeTrailingSlash($sDirectory);
$handle = opendir($cDirectory);
while ($file = readdir($handle)) {
if ($file == '.' || $file == '..') {
continue;
}
if (is_dir($cDirectory . $file)) {
deleteFiles($filter, $cDirectory . $file);
}
if (eregi($filter, $file)) {
unlink($cDirectory . $file);
}
}
closedir($handle);
}
function includeTrailingSlash($path) {
if (!eregi("/$", $path)) {
$path .= "/";
}
return $path;
}
You could then call that like this...
deleteFiles("\.html$", getenv('DOCUMENT_ROOT'));
... to remove all filenames ending in .html from the document root!
I hope this helps!
Regards,
Steve
More information about the thelist
mailing list