Walk a directory/Recursively: Difference between revisions

Added PHP implementation
m (Fixed lang tags.)
(Added PHP implementation)
Line 465:
my $pattern = 'foo';
find sub {print $File::Find::name if /$pattern/}, $dir;</lang>
 
=={{header|PHP}}==
<lang PHP>function findFiles($dir = '.', $pattern = '/./'){
$prefix = $dir . '/';
$dir = dir($dir);
while (false !== ($file = $dir->read())){
if ($file === '.' || $file === '..') continue;
$file = $prefix . $file;
if (is_dir($file)) findFiles($file, $pattern);
if (preg_match($pattern, $file)){
echo $file . "\n";
}
}
}
findFiles('./foo', '/\.bar$/');</lang>
 
This implementation uses Perl compatible regular expressions to match the whole path of the file
 
=={{header|Pop11}}==
Anonymous user