dongzhuzhou4504 2015-12-07 11:20
浏览 53
已采纳

递归地要求所有文件

I am trying to add all files in my project recursively, for this I have used this function:

<?php

function RequireFiles()
{
    $directory = new RecursiveDirectoryIterator(abspath . "lib/");
    $recIterator = new RecursiveIteratorIterator($directory);

    foreach ($recIterator as $item)
    {
        print $item->getPathname() . "<br />";
        //include $item->getPathname();
    }
}

?>

taken from here with minor changes.

My problem is that my output looks like this:

E:/projects/php/project/project/lib.
E:/projects/php/project/project/lib..
E:/projects/php/project/project/lib\class.
E:/projects/php/project/project/lib\class..
E:/projects/php/project/project/lib\class\Log.php
E:/projects/php/project/project/lib\trait.
E:/projects/php/project/project/lib\trait..
E:/projects/php/project/project/lib\trait\SetLink.php
E:/projects/php/project/project/lib\trait\MysqliEsp.php
E:/projects/php/project/project/lib\arrays.
E:/projects/php/project/project/lib\arrays..
E:/projects/php/project/project/lib\arrays\tables.php

I do not want to have the \. and \.. on the end and have looked for an answer for this for a while and cannot find out how to rid myself of these little terrors!

Can someone help me to fix this or point me in the direction of a Q&A that does?

  • 写回答

3条回答 默认 最新

  • douzhu3654 2015-12-07 11:32
    关注

    Just pass the flag FilesystemIterator::SKIP_DOTS in the constructor, e.g.

    $directory = new RecursiveDirectoryIterator(abspath . "lib/"
                                                , FilesystemIterator::SKIP_DOTS);
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大