std::filesystem::path::parent_path

Returns the path to the parent directory.

# Declarations

path parent_path() const;

(since C++17)

# Return value

The path to the parent directory, or a copy of *this if not has_relative_path().

# Example

#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
 
int main()
{
    for (fs::path p : {"/var/tmp/example.txt", "/", "/var/tmp/."})
        std::cout << "The parent path of " << p
                  << " is " << p.parent_path() << '\n';
}

# See also