Display directory listings on a page

Hey,

I’m wondering if there is a way to display the directory listings of a folder on my server directly on a grav page?
Assume there is a directory with subfolders containing pdfs. What I want is simple tree-structured listing of all the files and subfolders.

I’ve found this as the quickest solution via PHP: the scandir-command.
But how would I apply this, if this is even possible?

$files = array_slice(scandir('/directory/path/'), 2);

Wrap it into a plugin which exposes $files as a Twig-variable. If you want some dressing on it, there are also some quite nice JS-plugins for structuring the resulting tree.

Hi OleVik,
thanks for your reply. What you propose exceeds my competence at this point.

I’ve found this: https://github.com/lorenzos/Minixed
And it works like a charm so far. (Apart from daring making any changes at all.)
This displays the directory list in an .php-file (index.php). As far as I see there is no way to include this file to a specific page, isn’t there?

Would I be able to display what is generated in that index.php, I’d be content~

The Minixed-library/file is nice, though a bit limited in terms of what can be integrated with Grav. I do agree, however, that the style is rather pleasant, so I wrapped it into a plugin along with the necessary functionality to traverse files within Grav’s page-structure (limited to the current page) to show and link to files.

You can find the plugin here.

Nice! The preview on GitHub looks really neat. I’m using the learn2 framework. Is it going to work for me?
I installed the plugin and just put {{ directorylisting }} at the end of a page just to look what happens. Now two child-categories are showing from the side-menue.

How would I proceed to import the files listed that are displayed on index.php from minixed-library?

Yes, the child-categories (pages) appear because the plugin acts recursively on all folders and pages from whence it emanates. I will look into an option for excluding registered children from the structure as well as the main page.

Are you thinking of showing files above where the plugin is instantiated? Ie., files in parent folders? The plugin deliberately only lists folders/files below itself as a security measure, as other files should not be listed because they may contain indeliberate content that you do not want revealed.

I added an option for excluding modular pages, v1.0.4 should be available through the GPM shortly.