Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

boost::filesystem relative path and current directory?

How can I use boost::filesystem::path to specify a relative path on Windows? This attempt fails:

boost:filesystem::path full_path("../asset/toolbox"); // invalid path or directory. 

Maybe to help me debug, how to get the current working directory with boost::filesystem?

like image 348
Jake Avatar asked Oct 14 '10 17:10

Jake


People also ask

What is boost :: filesystem :: path?

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).

What is boost directory?

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.


2 Answers

getcwd = boost::filesystem::path full_path(boost::filesystem::current_path()); 

Example:

boost::filesystem::path full_path(boost::filesystem::current_path()); std::cout << "Current path is : " << full_path << std::endl; 

To access current_path one needs to add #include <boost/filesystem.hpp>.

like image 81
hmuelner Avatar answered Sep 18 '22 09:09

hmuelner


Try the system_complete function.

namespace fs = boost::filesystem;  fs::path full_path = fs::system_complete("../asset/toolbox"); 

This mimics exactly how the OS itself would resolve relative paths.

like image 36
ulidtko Avatar answered Sep 19 '22 09:09

ulidtko