I expect there is a simple way of doing this but I haven't been able to uncover this even with some intense googling.
How can I use boost::filesystem to find the location a symlink ( on *nix systems ) points to?
If you are using v3 of boost::filesystem
you can use the canonical function to get a path with all symlinks resolved. This may work for resolving the path of your symlink.
For example, if sym.link is a symlink:
boost::filesystem::path resolved = boost::filesystem::canonical( 'sym.link' );
I've not actually tried this so I could be wrong, but seems to make sense.
Alternatively, you might have some luck with read_symlink
You can use the read_symlink()
function of Version 3:
path read_symlink(const path& p); path read_symlink(const path& p, system::error_code& ec);
Returns: If
p
resolves to a symbolic link, a path object containing the contents of that symbolic link. Otherwise an empty path object.Throws: As specified in Error reporting. [Note: It is an error if p does not resolve to a symbolic link. -- end note]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With