Eliminate symbolic links with boost file system

I expect there is an easy way to do this, but I have not been able to reveal it even with an intensive search.

How can I use boost :: filesystem to find the location the symbolic link points to (on * nix systems)?

+9
c ++ boost linux filesystems
source share
2 answers

If you are using v3 from boost::filesystem , you can use the canonical function to get the path with all allowed symbolic links. This may work to resolve the path of your symbolic link.

For example, if sym.link is a symbolic link:

 boost::filesystem::path resolved = boost::filesystem::canonical( 'sym.link' ); 

I didn't really try this, so I could be wrong, but it seems to make sense.

Alternatively, you might be lucky with read_symlink

+12
source share

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 this symbolic link. Otherwise, an empty path object.

Throws: as indicated in the error message. [Note: p error is not resolved before the symlink. - end of note]

+5
source share

All Articles