douyue1481 2014-04-29 19:16
浏览 7
已采纳

仅获取文件夹名称的问题

I am using this code to list the name of ll existing Folders in a Directory but it is returning all folders, images, files (every thing) in the directory.

<?php
// open this directory 
$myDirectory = opendir($_SERVER['DOCUMENT_ROOT'] . "/.");
$list = 0;

while (false !== ($entryName = readdir($myDirectory))) {
if ($entryName != "." && $entryName != ".." && $entryName != ".DS_Store") {
$dirArray[] = $entryName;
}

}

Can you please let me know how to modify it to get ONLY Folders Name in the directory?

  • 写回答

1条回答 默认 最新

  • doujianzi8521 2014-04-29 19:33
    关注

    I think this will work:

    <?php
    $foldersandfiles = scandir($_SERVER['DOCUMENT_ROOT'] . "/.");
    
    foreach( $foldersandfiles as $folderorfile ) {
        if( $folderorfile != '.' && $folderorfile != '..' && is_dir($_SERVER['DOCUMENT_ROOT'] . '/' . $folderorfile) ) {
            $dirArray[] = $folderorfile;
        }
    }
    

    Please give it a go.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求会做山景bo1048b2程序的 直播声卡用
  • ¥15 51单片机与数码管实现电子琴
  • ¥15 h3.6m 人类行为预测论文复现
  • ¥50 wordpress项目注册报失败刷新后其实是成功状态,请求排查原因
  • ¥20 linxu服务器僵尸进程不释放,代码如何修改?
  • ¥15 pycharm激活不成功
  • ¥40 如果update 一个列名为参数的value
  • ¥15 基于51单片机的水位检测系统设计中LCD1602一直不显示
  • ¥15 OCS2安装出现问题,请大家给点意见
  • ¥15 ros小车启动launch文件报错