php path www nnews nnov ru scanDir function path regexp use scanDir dh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
$path = './www.nnews.nnov.ru';
$scanDir = function ($path, $regexp) use (&$scanDir) {
$dh = opendir($path);
while (($file = readdir($dh)) !== false) {
if ($file == '.' || $file == '..') {
continue;
}
$filename = $path . '/' . $file;
if (is_dir($filename)) {
foreach ($scanDir($filename, $regexp) as $result) {
yield $result;
}
} else if (preg_match($regexp, $filename)) {
yield $filename;
}
}
closedir($dh);
};
foreach ($scanDir($path, '#/news/\d{4}/\d\d/\d\d/.*?\.htm$#i') as $filename) {
printf("\t%s\n", $filename);
}