std::filesy...th::filename(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ std::filesystem::path::filename πŸŽ€

okay bestie, welcome to the std::filesy...th::filename(3) page from the C++ Standard Libary manual β€” yep, manual name folded in right here, no boring header line for us πŸ’…βœ¨


πŸ’– NAME πŸ’–

  • std::filesystem::path::filename - std::filesystem::path::filename

like, that's the name and also the name again. iconic. 🫢

πŸ¦‹ Synopsis πŸ¦‹

path filename() const;  (since C++17)

It returns the generic-format filename component of the path. no cap.

It's equivalent to relative_path().empty() ? path() : *--end() β€” literally that.

🌸 Parameters 🌸

(none) β€” zero, zilch, nada, no parameters bestie. πŸ“

✨ Return value ✨

The filename identified by the path. that's it, that's the tea. periodt.

πŸ”₯ Exceptions πŸ”₯

⚠️ May throw implementation-defined exceptions. so like, keep that in mind, mwah.

🧚 Example 🧚

// Run this code

#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;

int main()
{
    std::cout << fs::path("/foo/bar.txt").filename() << '\n'
              << fs::path("/foo/.bar").filename() << '\n'
              << fs::path("/foo/bar/").filename() << '\n'
              << fs::path("/foo/.").filename() << '\n'
              << fs::path("/foo/..").filename() << '\n'
              << fs::path(".").filename() << '\n'
              << fs::path("..").filename() << '\n'
              << fs::path("/").filename() << '\n'
              << fs::path("//host").filename() << '\n';
}

πŸ“ Output: πŸ“

"bar.txt"
".bar"
""
"."
".."
"."
".."
""
"host"

🌈 See also 🌈

  • extension β€” returns the file extension path component (public member function)
  • stem β€” returns the stem path component (filename without the final extension) (public member function)
  • replace_filename β€” replaces the last path component with another path (public member function)
  • has_filename β€” checks if the corresponding path element is not empty (public member function)

byeee bestie πŸ«ΆπŸ’‹ β€” source is http://cppreference.com, version/date is 2024.06.10, and this cutie page is std::filesy...th::filename(3). mwah, slay, periodt ✨

πŸ“¦ where this page comes from