#include <ext/path>
Adds cross-platform string and wide-string path helpers. Tests cover Windows-style and POSIX-style relative markers, existence checks, dirname/basename behavior, and multiple join cases.
ext::path::seperator<char>()andseperator<wchar_t>()return the platform path separator. The misspelled name is the current public API.ext::path::basename(path)anddirname(path)split the final component from its parent directory.ext::path::exists(path)checks whether a path exists.ext::path::is_relative(path)recognizes./name,../name,.\name, and..\nameas relative path forms.ext::path::join(base, child, ...)joins path components while applying./and../segments.- Overloads exist for
const CharT *andstd::basic_string<CharT>. - Variadic
joinis used when the compiler supports variadic templates andstd::index_sequence; otherwise overloads are provided up to four child arguments.
- Both
std::stringandstd::wstringpath overloads are supported where the platform API allows it. - A bare
.or..is not considered a relative path byis_relative; the tests require an actual child component. basenameanddirnamereturn an empty string when the input has no platform separator.jointreats./as current-directory noise and../as a request to move the accumulated path to its dirname before appending the remaining child path.joindoes not perform filesystem canonicalization, symlink resolution, or absolute-path security checks. It is string manipulation.- On non-Windows platforms, wide-path
existsconverts through the string conversion helper before callingstat.
- GCC 8.3.0+
- Clang 10.0+
- Visual Studio 2008 SP1+
#include <ext/path>
ext::path::seperator<char>(); // '/' on POSIX, '\\' on Windows
ext::path::basename("/aaa/bbb/file.txt"); // "file.txt"
ext::path::dirname("/aaa/bbb/file.txt"); // "/aaa/bbb"
ext::path::join("aaa", "bbb", "ccc"); // "aaa/bbb/ccc" on POSIX
ext::path::join("aaa/bbb", "../ccc"); // "aaa/ccc" on POSIX
ext::path::is_relative("./test"); // true
ext::path::is_relative("../test"); // true
ext::path::is_relative("/test"); // false
ext::path::exists("/test"); // platform filesystem check