So I run my app. I need for it to know where its executable is. How to find path to it using Boost.Filesystem?
boost::filesystem::path is the central class in Boost. Filesystem for representing and processing paths. Definitions can be found in the namespace boost::filesystem and in the header file boost/filesystem. hpp . Paths can be built by passing a string to the constructor of boost::filesystem::path (see Example 35.1).
For Windows system at console you can use system( dir ) command. And console gives you information about directory and etc. Read about the dir command at cmd .
The Boost Filesystem Library provides portable facilities to query and manipulate paths, files, and directories. The motivation for the library is the need to be able to perform portable script-like operations from within C++ programs.
boost::filesystem::system_complete(argv[0]);
e.g.
[davka@bagvapp Debug]$ ./boostfstest
/home/davka/workspaces/v1.1-POC/boostfstest/Debug/boostfstest
Note that this gives you the full path including the executable file name.
You cannot, Boost.Filesystem does not provide such functionality.
But starting with Boost 1.61 you can use Boost.Dll and function boost::dll::program_location
:
#include <boost/dll.hpp>
boost::dll::program_location().parent_path();
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