PHP RecursiveDirectoryIterator

前端 未结 3 1783
一向
一向 2020-12-11 18:20

I want to do a RecursiveDirectoryIterator on a set of folders in a directory, say ./temp and then list the files in each folder according to the name of the fol

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-11 19:01

    //Managed to put this together and it somehow works for me. If you have other options please provide. Thanks
    
    $path='./temp';
    $dir  = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
    $files = new RecursiveIteratorIterator($dir, RecursiveIteratorIterator::CHILD_FIRST);
    
        foreach ($files as $file=>$mykey) {
            if(is_dir($file)) {
    
    $directory = $file;
    $mydir = new RecursiveIteratorIterator(new RecursiveRegexIterator(new RecursiveDirectoryIterator($directory,RecursiveDirectoryIterator::FOLLOW_SYMLINKS), 
    // match both pdf file extensions and directories
                    '#(?$mykey) {
        $result[] = $myfile.'
    '; $filetypes = array("pdf"); $filetype = pathinfo($myfile, PATHINFO_EXTENSION); if (in_array(strtolower($filetype), $filetypes)) { // output all matches substr(dirname($file),11) ?>
    >
    getFilename(), '.pdf') !== FALSE) {?>

提交回复
热议问题