php scandir - >搜索文件/目录

Pet*_*ter 5 php

在我问之前我搜索过,没有幸运..

我为自己寻找一个简单的脚本,我可以搜索文件/文件夹.在php手册中找到了这段代码片段(我想我需要这个),但它对我不起作用.

"正在寻找一种使用掩码搜索文件/目录的简单方法.这是一个这样的功能.

默认情况下,此函数会在内存中保留scandir()结果,以避免为同一目录扫描多次."

<?php 
function sdir( $path='.', $mask='*', $nocache=0 ){ 
    static $dir = array(); // cache result in memory 
    if ( !isset($dir[$path]) || $nocache) { 
        $dir[$path] = scandir($path); 
    } 
    foreach ($dir[$path] as $i=>$entry) { 
        if ($entry!='.' && $entry!='..' && fnmatch($mask, $entry) ) { 
            $sdir[] = $entry; 
        } 
    } 
    return ($sdir); 
} 
?>
Run Code Online (Sandbox Code Playgroud)

感谢您的任何帮助,

彼得

Art*_*cto 3

$a = new RegexIterator(
    new RecursiveIteratorIterator(
        new RecursiveDirectoryIterator('DIRECTORY HERE')
    ),
    '/REGEX HERE/',
    RegexIterator::MATCH
);

foreach ($a as $v) {
    echo "$v\n"; //$v will be the filename
}
Run Code Online (Sandbox Code Playgroud)