# Is it possible to ignore directories inside a staticDir?

**URL:** <https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736>\
**Category:** support\
**Created:** [May 16, 2019, 3:39am UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736 "2019-05-16T03:39:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![w1res](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@w1res](https://discourse.gohugo.io/u/w1res)\
**Post date:** [May 16, 2019, 3:39am UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736/1 "2019-05-16T03:39:59Z")

</div>

Is it possible to ignore a directory inside staticDir?

I have a bootstrap theme that is built using gulp. It generates a `dist` folder containing a few subfolders: `dist/css`, `dist/fonts`, `dist/img`, `dist/video`, `dist/js`.

I only need the `dist/css` `dist/fonts` and `dist/js`, so I added those to hugo as staticDirs. The problem is that all the files are added to the website root, so the relative links get messed up.

If I was able to add the `dist` directory to the `staticDir`, then it would maintain the folder heirarchy and everything would work. The problem is that it also adds the theme’s `video` and `image` files, which I do not want. Is there any way to make them get ignored?

Another solution I’ve thought about is editing the theme’s files to fix the links, but that leaves a high likelihood of making a mistake. It also makes updating the theme much more difficult.

Lastly, I’ve also though about modifying the gulpfile to create a second folder just for the files I want to use in hugo, but I’m not that experienced with gulp and don’t think I could modify it properly (especially with all the fancy file watching, cleaning, etc. that the gulpfile is doing).

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [May 16, 2019, 3:50am UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736/2 "2019-05-16T03:50:27Z")

</div>

One idea: When you copy that dir over using gulp, instead of copying the full `dist` dir, copy on the subdirs you want

---

<div class="post-metadata">

**Author:** ![w1res](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@w1res](https://discourse.gohugo.io/u/w1res)\
**Post date:** [May 16, 2019, 3:54am UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736/3 "2019-05-16T03:54:17Z")

</div>

Thanks for the suggestion. That’s what I meant in the last paragraph, but the way the gupfile is structured makes it difficult (and I’m still new with gulp). I’d rather do it through hugo if at all possible so that way I won’t have to be modifying the theme’s files.

I’ll use your suggestion as a backup plan!

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [May 16, 2019, 3:57am UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736/4 "2019-05-16T03:57:23Z")

</div>

I see. Well, I’m not familiar with gulp, but this could easily be done with a bash script too. For example after the `dist` dir is copied over, run:

```
rm -r static/dist/img
rm -r static/dist/video
```

---

<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:** [May 16, 2019, 7:43am UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736/5 "2019-05-16T07:43:35Z")

</div>

Try `ignorefiles = ["/dist/video/.*", "dist/img/.*"]` in the config. This parameter goes before any TOML tables.

ref: [https://gohugo.io/getting-started/configuration/#ignore-files-when-rendering](https://gohugo.io/getting-started/configuration/#ignore-files-when-rendering)

---

<div class="post-metadata">

**Author:** ![w1res](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@w1res](https://discourse.gohugo.io/u/w1res)\
**Post date:** [May 16, 2019, 3:07pm UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736/6 "2019-05-16T15:07:07Z")

</div>

Thanks for the suggestion but it didn’t work. I tried a bunch of different strings and couldn’t get it to work.

I even tried using the example from the documentation `ignoreFiles = ["\\.foo$", "\\.boo$"]` but I replaced `foo` with `mp4` and the file was still being copied over.

---

<div class="post-metadata">

**Author:** ![ju52](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ju52/32/6749_2.png) [@ju52](https://discourse.gohugo.io/u/ju52)\
**Post date:** [May 16, 2019, 3:25pm UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736/7 "2019-05-16T15:25:29Z")

</div>

Hugo ignores files when rendering! Nothing to do with gulp.

---

<div class="post-metadata">

**Author:** ![w1res](https://avatars.discourse-cdn.com/v4/letter/w/958977/32.png) [@w1res](https://discourse.gohugo.io/u/w1res)\
**Post date:** [May 16, 2019, 5:36pm UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736/8 "2019-05-16T17:36:51Z")

</div>

gulp generates the static assets I need for my webpages into its own special directory structure that the theme developer chose. I’m attempting to point hugo’s staticDir to those assets, without copying unnecessary files (e.g., sample videos and sample images). If I pick and choose only the folders I want, then hugo flattens them into the sites root directory and all the relative links get broken.

From the answers I’m getting it seems that hugo is unable to do this at this point in time. My backup plan is to edit the bootstrap themes files to fix the relative links, but that was something I was hoping to avoid.

I did some searching on the hugo github repo, and it seems like this is an issue that someone has already created a [pull request](https://github.com/gohugoio/hugo/pull/5649) for.

---

<div class="post-metadata">

**Author:** ![\_nm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/_nm/32/7662_2.png) [@\_nm](https://discourse.gohugo.io/u/_nm)\
**Post date:** [May 22, 2019, 5:34pm UTC](https://discourse.gohugo.io/t/is-it-possible-to-ignore-directories-inside-a-staticdir/18736/9 "2019-05-22T17:34:05Z")

</div>

ignoreFiles is only relevant to the content directory. I posted about that here:

> [@Build only specific content sections](https://discourse.gohugo.io/t/build-only-specific-content-sections/16841/4):
>
> Another possibility is to use ignoreFiles in your config file, e.g., here’s part of my config.yaml: ignoreFiles: - UNPUBLISHED Note: ignoreFiles is only relevant to the content directory (but it would be great if it worked everywhere, e.g., in the static directory) each string in an ignoreFiles list is a regular expression (RE) looking for a match in the path, e.g. many of my bundles include a path like articles/bundlename/UNPUBLISHED/oldscreenshot.png if the RE is all lower case, it mat…

It would be useful if Hugo had other ignore variables like:

- ignoreStaticFiles
- ignoreLayoutFiles
- ignoreConfigFiles
- ignoreAssetFiles

The most useful would be ignoreStaticFiles since all those files get automatically copied to the publishDir.
