zoukankan      html  css  js  c++  java
  • php沥遍目录结构

    <?php
    $dir = "testFile";//假设当前页面同目录下有testFile文件夹
    //方式1
    $dirSource = opendir($dir);
    while ($childFileName = readdir($dirSource)) {
        if (!strcmp($childFileName, ".") || !strcmp($childFileName, "..")) {//排除testFile文件夹下最开始的 "."和".."两个文件名
            continue;
        }
        echo $childFileName . "目录列表:<br/><br/>";
        $childFileDir = "$dir/" . $childFileName;//子文件相对当前执php文件的路径
        $childDirLogoStr = "--";//子文件标识符号
        findAllChildFileName($childFileDir, $childDirLogoStr);
    }
    
    //方式2,直接调用方法把路径传进去也可沥遍所有结构
    //findAllChildFileName($dir, "--");
    
    function findAllChildFileName($dir, $childDirLogoStr) {
        if (is_dir($dir)) {
            $dirSource = dir($dir);
            while ($childFileName = $dirSource->read()) {//和上面沥遍结果一样,只是方式有点变化
                if (!strcmp($childFileName, ".") || !strcmp($childFileName, "..")) {
                    continue;
                }
                $childFileDir = $dir . "/" . $childFileName;
                if (is_file($childFileDir)) {
                    echo $childDirLogoStr . $childFileName . ":文件<br/>";
                } else {
                    echo $childDirLogoStr . $childFileName . ":目录<br/>";
                    findAllChildFileName($childFileDir, "--" . $childDirLogoStr);
                }
            }
            $dirSource->close();
        }
    }
    ?>
  • 相关阅读:
    2020面向对象程序设计寒假作业2 题解
    题解 P3372 【【模板】线段树 1】
    Global variant VS local variant
    u2u
    深入浅出PowerShell系列
    深入浅出WF系列
    debug
    深入浅出SharePoint系列
    InfoPath debug
    深入浅出Nintex系列
  • 原文地址:https://www.cnblogs.com/dreamhome/p/2923660.html
Copyright © 2011-2022 走看看