C ++: Boost: how to check for a folder in another folder in my working directory?

the code:

boost::filesystem::path config_folder(Config::CONFIG_FOLDER_NAME); if( !(boost::filesystem::exists(config_folder))) { std::cout << "Network Config Directory not found...\n"; std::cout << "Creating folder called " << Config::CONFIG_FOLDER_NAME << "\n"; boost::filesystem::create_directory(config_folder); } if( !(boost::filesystem::exists(boost::format("%s/%s") % config_folder % Config::fmap[Config::current_hash_function])); { std::cout << "This hash has not been configure before...\n"; std::cout << "Creating folder called " << Config::fmap[Config::current_hash_function] << "\n"; boost::filesystem::create_directory(boost::format("%s/%s") % config_folder % Config::fmap[Config::current_hash_function]); } 

So, firstly, if the configuration folder does not exist, create it. (this part works) Then check if the current_hash_function folder exists, if not .. create it. (this part does not work)

The error I am getting;

 src/neural_networks/shared.cpp:41: error: no matching function for call to 'exists(boost::basic_format<char, std::char_traits<char>, std::allocator<char> >&)' 

the reason I made the forced format in fs: exists check is because I don't know how to create a level 2 path deep

+7
source share
2 answers

The / operator is overloaded to concatenate path objects. There is no need to explicitly format the strings, and there is no need to worry about the platform-specific path separator character.

 if(!(boost::filesystem::exists(config_folder / Config::fmap[Config::current_hash_function])); 

Any operand can be std::string if the other is path .

+10
source

boost::filesystem::exists() needs an argument like boost::filesystem::path or something that is implicitly convertible, like std::string , but what you pass in is neither one nor the other.

the following should work:

 if( !( boost::filesystem::exists( str( boost::format("%s/%s") % config_folder % Config::fmap[Config::current_hash_function]))) 
0
source

All Articles