打开子目录以读取其内容

时间:2014-10-22 18:46:05

标签: php loops directory

我的目录结构如下所示,我的脚本位于“alerts”目录中:

enter image description here

'subscribers'目录中的每个目录都有我想要读取的配置文件,但是,我很难打开'subscriber'中的子目录。例如,我似乎无法打开'MNTF'目录。

下面是我写的快速脚本,我错过了什么?

if($sub_handle = opendir('subscribers/')){
    while (false !== ($entry = readdir($sub_handle))) {
        if (substr($entry, 0, 1) == '.') {          
            continue;
        }   


        if($handle = opendir($entry)){      
            echo "in my second directory";
        }
        else{
            exit('cannot read subscriber');
        }        
    }
}
else{
    exit('nope');
}

当我回显$entry时,它会显示MNTF。屏幕上的输出为cannot read subscriber。我想要的结果是回应in my second directory

1 个答案:

答案 0 :(得分:0)

第二个opendir的路径相对于脚本的位置:

if($handle = opendir('subscribers/'.$entry)){   

这为我解决了。

相关问题