Search code examples
c++windowsboostnetworkcredentials

Is there a way to map a network drive (w/credentials) working with Boost?


I have the following code to check if a directory exists.

#include <boost/filesystem.hpp>
using namespace boost::filesystem;

try
{
    // Check whether the directory is valid
    if (!exists(dir) || !is_directory(dir))
    {
        return false;
    }
}
catch (filesystem_error const & e)
{
    return false;
}

Unfortunately it catches an error when trying to navigate to a folder on another PC on the network. If I try navigating to the folder using Windows explorer I am prompted for a username and password. If I enter these details and then run my code again it can find the folder and doesn't catch an error.

Is there any way I can enter network credentials in the code if I know what they will be?


Solution

  • Network credentials are completely unrelated to traversing filesystems.

    Instead, on windows, map the drive (e.g. use NET USE).

    Then you will be able to browse the mapped drive as any other location.

    So, direct answer: No. There is no way enter credentials with Boost. Neither should there be.