std::filesystem::path 有几种
dir/file.txt或dir\file.txt无cwd的路径片段.is_relative() == true.is_absolute() == false
./file1或.\file1相对当前目录的相对路径 (当前目录.).is_relative() == true.is_absolute() == false
/root/file1或C:\\Windows绝对路径
Win special
c:或C::is_relative() == truec:\或C:/:is_absolute() == true
std::filesystem::lexically_xx() lexically系列
‘lexically’ 字面上转换, 直接转换, 不论文件是否存在, 例如这个例子 https://en.cppreference.com/w/cpp/filesystem/canonical
std::filesystem::canonical()如果路径存在返回, 否则 exception / error_codestd::filesystem::weakly_canonical()不校验路径是否存在, 直接计算路径for example Current path is "/tmp/a/b/c1/d"
- canonical("../../c2/./e") == "/tmp/a/b/c2/e"
- weakly_canonical("../no-such-file") == "/tmp/a/b/c1/no-such-file"
- caronical("../no-such-file") => threw exception: filesystem error: in canonical: No such file or directory [../no-such-file] [/tmp/a/b/c1/d]
路径转换
- ABS绝对路径
absolute() - ABS绝对路径
canonical() - REL相对路径
proximate() - REL相对路径
relative() - 路径转换到 OS-perferred-sep
lexically_normal()