# How to tell FetchContent to keep archive directory structure

**URL:** https://discourse.cmake.org/t/how-to-tell-fetchcontent-to-keep-archive-directory-structure/8012
**Category:** Code
**Created:** [April 28, 2023, 3:47pm UTC](https://discourse.cmake.org/t/how-to-tell-fetchcontent-to-keep-archive-directory-structure/8012 "2023-04-28T15:47:40Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![r4stered](https://discourse.cmake.org/user_avatar/discourse.cmake.org/r4stered/32/3396_2.png) [@r4stered](https://discourse.cmake.org/u/r4stered)
#### Post date: [April 28, 2023, 3:47pm UTC](https://discourse.cmake.org/t/how-to-tell-fetchcontent-to-keep-archive-directory-structure/8012/1 "2023-04-28T15:47:40Z")

</div>

Hello,

I am downloading some header files from a remote URL and unzipping them using FetchContent. This works as expected, except for the fact that the zip files directory structure isn’t being kept the same.

For example, if I take a look at the zip file I am downloading in 7zip, the directory structure looks like this:

```auto
- foo/
  - bar/
    - example.h

```

But when using FetchContent like so:

```cmake
FetchContent_Declare(
  package_headers
  URL ${header_url}
)
FetchContent_MakeAvailable(package_headers)

```

The directory structure ends up like this

```auto
- build/
  - desktop_debug_shared
    - _deps
      - package_headers-src
        - bar/
          - example.h

```

This only seems to happen if the zip has only a folder in the top level dir and nothing else.

I would like to keep the top-level folder to keep the include path the same.

Any help is appreciated!

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [April 29, 2023, 6:38am UTC](https://discourse.cmake.org/t/how-to-tell-fetchcontent-to-keep-archive-directory-structure/8012/2 "2023-04-29T06:38:44Z")

</div>

The code that implements that behavior is in [extractfile.cmake.in](https://gitlab.kitware.com/cmake/cmake/-/blob/v3.26.3/Modules/ExternalProject/extractfile.cmake.in#L43-L58). There’s currently no option to prevent it from discarding a single top level directory. As a workaround, you can use the `DOWNLOAD_NO_EXTRACT` option to prevent extraction and then perform extraction manually yourself. I acknowledge that’s not ideal, but it is a workaround available to you since CMake 3.6.

---

<div class="post-metadata">

### Author: ![r4stered](https://discourse.cmake.org/user_avatar/discourse.cmake.org/r4stered/32/3396_2.png) [@r4stered](https://discourse.cmake.org/u/r4stered)
#### Post date: [April 29, 2023, 11:58am UTC](https://discourse.cmake.org/t/how-to-tell-fetchcontent-to-keep-archive-directory-structure/8012/3 "2023-04-29T11:58:54Z")

</div>

Thank you for tracking this behavior. I appreciate the workaround!
