std::filesystem::read_symlink
Min standard notice:
Header: <filesystem>
If the path p refers to a symbolic link, returns a new path object which refers to the target of that symbolic link.
# Declarations
std::filesystem::path read_symlink( const std::filesystem::path& p );
(since C++17)
std::filesystem::path read_symlink( const std::filesystem::path& p,
std::error_code& ec );
(since C++17)
# Parameters
p: path to a symlinkec: out-parameter for error reporting in the non-throwing overload
# Return value
The target of the symlink (which may not necessarily exist).
# Example
#include <filesystem>
#include <iostream>
namespace fs = std::filesystem;
int main()
{
for (fs::path p : {"/usr/bin/gcc", "/bin/cat", "/bin/mouse"})
{
std::cout << p;
fs::exists(p) ?
fs::is_symlink(p) ?
std::cout << " -> " << fs::read_symlink(p) << '\n' :
std::cout << " exists but it is not a symlink\n" :
std::cout << " does not exist\n";
}
}