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条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题