Use manipulation functions with path
The filesystem library includes functions for manipulating the contents of path objects. In this recipe, we will consider a few of these tools.
How to do it…
In this recipe, we examine some functions that manipulate the contents of path objects:
- We start with the
namespacedirective and ourformatterspecialization. We do this in every recipe in this chapter:namespace fs = std::filesystem; template<> struct std::formatter<fs::path>: std::formatter<std::string> { Â Â Â Â template<typename FormatContext> Â Â Â Â auto format(const fs::path& p, FormatContext& ctx) { Â Â Â Â Â Â Â Â return format_to(ctx.out(), "{}", p.string()); Â Â Â Â } }; - We can get the current working directory with the
current_path()function, which returns apathobject:cout << format("current_path: {}\n", fs::current_path...