# List posts filtered by directory

**URL:** <https://discourse.gohugo.io/t/list-posts-filtered-by-directory/19106>\
**Category:** support\
**Created:** [June 8, 2019, 8:19pm UTC](https://discourse.gohugo.io/t/list-posts-filtered-by-directory/19106 "2019-06-08T20:19:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dominik.mayer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dominik.mayer/32/8898_2.png) [@dominik.mayer](https://discourse.gohugo.io/u/dominik.mayer)\
**Post date:** [June 8, 2019, 8:19pm UTC](https://discourse.gohugo.io/t/list-posts-filtered-by-directory/19106/1 "2019-06-08T20:19:38Z")

</div>

Given the following structure of the content folder:

```auto
- blog
  ├─ 2019
  ├─ myoldposts
  | ├─ 2008
  | └─ 2009
  └─ shares
     ├─ 2019
     └─ migrated
        ├─ 2014
        └─ 2015

```

How can I list pages only from `shares` plus subdirectories?

I can use

```auto
range (where .Pages ".File.Dir" "in" "blog/shares/migrated/2014/")

```

to filter for the lowest subdirectory.

But when I try to go one level up it doesn’t work anymore:

```auto
range (where .Pages ".File.Dir" "in" "blog/shares/migrated/")

```

Using comparators like `ge` doesn’t work either.

Is there no function that checks for a substring?

Similar problems that got solved in other ways:

- [[Solved] Problem with "where in" construct](https://discourse.gohugo.io/t/solved-problem-with-where-in-construct/7315/2)
- [List all pages under a sub-section folder](https://discourse.gohugo.io/t/list-all-pages-under-a-sub-section-folder/6789)

---

<div class="post-metadata">

**Author:** ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)\
**Post date:** [June 8, 2019, 8:28pm UTC](https://discourse.gohugo.io/t/list-posts-filtered-by-directory/19106/2 "2019-06-08T20:28:21Z")

</div>

> [@dominik.mayer](#):
>
> Is there no function that checks for a substring?

Have a look also in this thread:

> [@Iterating over sub-directories inside a directory](https://discourse.gohugo.io/t/iterating-over-sub-directories-inside-a-directory/19044):
>
> Consider the following directory structure in the root directory of a hugo static site: content | └── A └──A1 ├── a.md └── b.md └──A2 ├── a.md └── b.md └──A3 ├── a.md └── b.md . . . All I want to do is render the ‘Content’ of the markdown files; but I want to do this directory-wise i.e., I want a separate row for all the sub-directories viz. A1, A2,… and inside each row, I want the content of the…

---

<div class="post-metadata">

**Author:** ![dominik.mayer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dominik.mayer/32/8898_2.png) [@dominik.mayer](https://discourse.gohugo.io/u/dominik.mayer)\
**Post date:** [June 8, 2019, 8:43pm UTC](https://discourse.gohugo.io/t/list-posts-filtered-by-directory/19106/3 "2019-06-08T20:43:14Z")

</div>

Merci. As far as I can see that post tackles a similar issue. Difference seems to be that I don’t want posts grouped by subfolder. I want them all listed in the blog but also have a page where I list a subset.

So the question is: How do I get an array of all the posts stored below a specific folder.

---

<div class="post-metadata">

**Author:** ![dominik.mayer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dominik.mayer/32/8898_2.png) [@dominik.mayer](https://discourse.gohugo.io/u/dominik.mayer)\
**Post date:** [June 9, 2019, 6:01am UTC](https://discourse.gohugo.io/t/list-posts-filtered-by-directory/19106/4 "2019-06-09T06:01:34Z")

</div>

Another thing I’ve played around with is `findRE`. Unfortunately I can’t get it to work in `where` either:

Because `findRE` is not a valid operator in `where` I can’t do:

```auto
{{ $posts := where .Pages ".FileDir" "findRE" $path }}

```

And this doesn’t work because “.FileDir” is treated as a string:

```auto
{{ $posts := where .Pages (len (findRE $path ".FileDir")) "gt" 0 }}

```
