std::filesystem::path::remove_filename
From cppreference.com
 
 
 < cpp | filesystem | path 
 
 
 C++ 
 Feature test macros (C++20)
 Concepts library (C++20)
 Metaprogramming library (C++11)
 Ranges library (C++20)
 Filesystem library (C++17)
 Concurrency support library (C++11)
 Execution control library (C++26)
std::filesystem::path 
 
 
 
 
 
 
 
 
 
 
path::remove_filename
(until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
path& remove_filename();
 
 (since C++17) 
Removes a single generic-format filename component (as returned by filename) from the given generic-format path.
After this function completes, has_filename returns false.
[edit] Parameters
(none)
[edit] Return value
*this
[edit] Exceptions
May throw implementation-defined exceptions.
[edit] Example
Run this code
#include <filesystem> #include <iostream> namespace fs = std::filesystem; int main() { fs::path p; std::cout << std::boolalpha << (p = "foo/bar").remove_filename() << '\t' << p.has_filename() << '\n' << (p = "foo/").remove_filename() << '\t' << p.has_filename() << '\n' << (p = "/foo").remove_filename() << '\t' << p.has_filename() << '\n' << (p = "/").remove_filename() << '\t' << p.has_filename() << '\n' << (p = "").remove_filename() << '\t' << p.has_filename() << '\n'; }
Output:
"foo/" false "foo/" false "/" false "/" false "" false