Skip to content

Feature: walker function: walker(".") returns an object model of the entire directory / an expansive alternative for scandir() #22104

@patrpatl

Description

@patrpatl

Description

Here is my current code for demonstrating the purpose. The dev community shall decide on the final verdict.

<?php
    function walker($directory) {
        foreach (scandir($directory) as $item) {
            if ($item == '.' || $item == '..') continue;
            if ($directory == "." && ($item == "api.php" || $item == 'index.html')) continue;
            $dl[$item] = [
                "item_type" => is_dir("{$directory}/{$item}") ? "folder" : "file",
                "child" => walker("{$directory}/{$item}"),
            ];
        }
        return $dl;
    }
?>

Here's how I'm currently using it :) with some html css and js
Image

How it looks like when I use echo and json_encode.
Image

I'll be making a pull request if it got a lot of good impressions.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions