# Listing files in directory

**URL:** <https://talk.jekyllrb.com/t/listing-files-in-directory/4434>\
**Category:** Help\
**Created:** [May 15, 2020, 1:37pm UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434 "2020-05-15T13:37:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![LorenzBung](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lorenzbung/32/2505_2.png) [@LorenzBung](https://talk.jekyllrb.com/u/LorenzBung)\
**Post date:** [May 15, 2020, 1:37pm UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/1 "2020-05-15T13:37:52Z")

</div>

Hi, I have a quick question.

Is it possible to make Jekyll display a file overview when accessing a directory path? Example:

```nohighlight
my-repo
  +--index.md
  +--_posts/
  | +--2020-04-04-some-post.md
  | +--2020-04-05-another-post.md
  +--some-directory/
  | +--some-file.html
  | +--another-file.html
  +--_layout/

```

When running `bundle exec jekyll serve`, the file `http://127.0.0.1:4000/some-directory/some-file.html` will be accessible. However, I want a list of files when accessing `http://127.0.0.1:4000/some-directory`.

One possibility is to create a file manually, containing a link to every file in that directory. But is there a possibility to auto-generate a page, or (even better), use some browser built-in (like when accessing `file:///var/log`)?

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [May 15, 2020, 4:29pm UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/2 "2020-05-15T16:29:42Z")

</div>

If you want to do that with a _built_ site , I can recommend python built server. It gives you a folder overview in the browser if there is no index.html in the current folder.

```auto
cd _site
python3 -m http.server 4000

```

You can even run this from the project root to view your source files as folder. but anything not html such as markdown will be viewed as plain text or get prompted to download it to Downloads

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [May 15, 2020, 4:31pm UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/3 "2020-05-15T16:31:04Z")

</div>

In terms of standard Jekyll serve to view a site…

If you want to iterate over a directory to build up a visitor facing menu or table of contents you can iterate over

```auto
{{ site.pages }}

```

And use the page.title or page.path etc.

And it can be filtered to just the current subdirectory.

---

<div class="post-metadata">

**Author:** ![LorenzBung](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lorenzbung/32/2505_2.png) [@LorenzBung](https://talk.jekyllrb.com/u/LorenzBung)\
**Post date:** [May 15, 2020, 4:48pm UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/4 "2020-05-15T16:48:28Z")

</div>

Is there also a solution that works on Github Pages?

Using the `{{ site.pages }}` method and applying a filter would also mean I’d have to manually create a file for each directory.

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [May 15, 2020, 6:50pm UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/5 "2020-05-15T18:50:27Z")

</div>

A page knows its own path

```auto
{{ page.path }}

```

so you just filter dynamically to pages which are in the same directory (or below) for the current page. This can be done once as a layout and reused

My plan is to use this to have a project with multiple nested levels but the index.md at each level uses a common layout and shows the table of contents for the directory

---

<div class="post-metadata">

**Author:** ![LorenzBung](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lorenzbung/32/2505_2.png) [@LorenzBung](https://talk.jekyllrb.com/u/LorenzBung)\
**Post date:** [May 16, 2020, 3:06pm UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/6 "2020-05-16T15:06:45Z")

</div>

Yes, I know that. But if I access the pages in the directory using Liquid, I still have to create a file for each directory manually. My question is if there is an option to make Jekyll generate such an overview automatically, or enable the browser built-in directory view on GitHub pages.

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [May 17, 2020, 1:48am UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/7 "2020-05-17T01:48:04Z")

</div>

directory browsing/listing as I have seen it is a function of the webserver - what you want in your 1st post is what I usually see happen when running jekyll serve - if you pull up a directory only (no index.html file) I usually see a list of files - but I have all my files output at index.html inside a folder with the title - so `some-file.html` would not exist - it would be `some-file/index.html`.

If in the browser I put `/some-directory/` I would get a file list (haven’t done this in a long time so could be wrong now) as there would be no index file there and the built in webserver for jekyll I think does have `enable directory listing` turned on. But that is just locally. My understanding is that this is a really bad practice to have this enabled for public websites as it would show anything and everything which could show all kinds of files with secret keys and what not.

So if you want this locally, I think it is possible and may have to do with the permalink structure if it is not working for you.

If you want this on GH then I don’t think it is going to happen without you somehow creating it which I can’t see an easy way to do.

---

<div class="post-metadata">

**Author:** ![LorenzBung](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/lorenzbung/32/2505_2.png) [@LorenzBung](https://talk.jekyllrb.com/u/LorenzBung)\
**Post date:** [May 17, 2020, 7:04am UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/8 "2020-05-17T07:04:19Z")

</div>

Ahh, hm that makes sense. Than you for your answer!

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [May 17, 2020, 7:19am UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/9 "2020-05-17T07:19:22Z")

</div>

Great. I didn’t know about that feature

The Python server option will I mentioned above will do the same thing for a directory, just lacking the Jekyll server features.

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [May 17, 2020, 7:37am UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/10 "2020-05-17T07:37:16Z")

</div>

Its `jekyll serve --show-dir-listing` and it works for me. It ignores an index file is there is one.

---

<div class="post-metadata">

**Author:** ![MichaelCurrin](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/michaelcurrin/32/2340_2.png) [@MichaelCurrin](https://talk.jekyllrb.com/u/MichaelCurrin)\
**Post date:** [May 17, 2020, 9:19am UTC](https://talk.jekyllrb.com/t/listing-files-in-directory/4434/11 "2020-05-17T09:19:34Z")

</div>

The flag is needed to replace index.html but otherwise you can omit the flag and see the directory listing. I just tested

It turns out no change was needed and the functionality was builtin all along.
