# Go to parent directory - just search for / ?

**URL:** https://discourse.cmake.org/t/go-to-parent-directory-just-search-for/7312
**Category:** Development
**Created:** [January 23, 2023, 10:34pm UTC](https://discourse.cmake.org/t/go-to-parent-directory-just-search-for/7312 "2023-01-23T22:34:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![neundorf](https://discourse.cmake.org/user_avatar/discourse.cmake.org/neundorf/32/2075_2.png) [@neundorf](https://discourse.cmake.org/u/neundorf)
#### Post date: [January 23, 2023, 10:34pm UTC](https://discourse.cmake.org/t/go-to-parent-directory-just-search-for/7312/1 "2023-01-23T22:34:24Z")

</div>

Hi,

if I have some path in a std::string inside CMake, what’s the recommended way to get the parent directory of that path ?  
Just search for the slashes, or something else ?

Thanks  
Alex

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [January 23, 2023, 10:43pm UTC](https://discourse.cmake.org/t/go-to-parent-directory-just-search-for/7312/2 "2023-01-23T22:43:06Z")

</div>

You can include ‘cmCMakePath.h’ header which provides `cmCMakePath` class.

This class offers the same capabilities as [std::filesystem::path](https://en.cppreference.com/w/cpp/filesystem/path).
