【问题标题】:php list in array files in dir and sub dirs etc. that match pattern.目录和子目录等中匹配模式的数组文件中的 php 列表。
【发布时间】:2010-12-19 09:53:39
【问题描述】:

我希望列出目录中的所有文件及其与模式匹配的子目录,并将列表作为数组返回以供以后使用。我实际上也想传递一组目录来执行此操作。

【问题讨论】:

    标签: php file design-patterns directory


    【解决方案1】:
    
    $dirs= new ArrayIterator(array('./', '/dir_two'));
    $list = array();
    foreach($dirs as $dir){
        $dir_iterator = new RecursiveDirectoryIterator($dir);
        $iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
    
        foreach($iterator as $file){
            if(preg_match('~.*~',$file->getFilename()))
                    array_push($list,$file->getPathname());
        }
    }
    print_r($list);
    
    

    【讨论】:

      【解决方案2】:

      glob,但可能是这些模式没有足够的表达能力来满足您的需求。它使用与 shell 相同的模式,而不是正则表达式。

      【讨论】:

        猜你喜欢
        • 2013-01-07
        • 1970-01-01
        • 2014-05-02
        • 1970-01-01
        • 2017-10-08
        • 2020-01-23
        • 1970-01-01
        • 2015-06-14
        • 1970-01-01
        相关资源
        最近更新 更多