RecursiveIteratorIterator返回。和...为每个目录

时间:2015-06-13 09:24:10

标签: php

我使用RecursiveIteratorIterator来获取Linux中的递归目录列表但是当我尝试获取目录时,我有每个目录的拖曳版本。和..这样:

  'dirs' => 
    array (size=13)
      0 => string './..' (length=4)
      1 => string './..' (length=4)
      2 => string './.' (length=3)
      3 => string './.idea/..' (length=10)
      4 => string './.idea/.' (length=9)
      5 => string './.idea/scopes/..' (length=17)
      6 => string './.idea/scopes/.' (length=16)
      7 => string './images/..' (length=11)
      8 => string './images/.' (length=10)
      9 => string './test/..' (length=9)
      10 => string './test/.' (length=8)
      11 => string './test/test2/..' (length=15)
      12 => string './test/test2/.' (length=14)

我的代码是:

$files = [ 'files' => [ ], 'dirs' => [ ] ];

  $directories = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('.'));
            while ($directories->valid())
            {

                if ($directories->isFile())
                {
                    $files['files'][] = $directories->getPathName();
                } elseif ($directories->isDir())
                {
                    $files['dirs'][] = $directories->getPathName();
                }

                $directories->next();
            }

当我使用RecursiveDirectoryIterator::SKIP_DOTS类似吹码时:

        $directories = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS));

我没有任何结果。

0 个答案:

没有答案