Image Export: Create folder if not existing

I want to save a snapshot of the view. When the path exists, it works fine. But if a folder in the path is not existing, I get an exception. Is there a way to create the missing folders ?

HPS::Image::ExportOptionsKit export_options;
	export_options.SetSize(800, 450);

	HPS::Image::File::Export("C:/temp/test/testExport.png", GetCanvas().GetWindowKey(), export_options);

Hello Julian,

HOOPS does not have a API to create folder.

You can use the following code in C++ 17 to achieve this

#include <filesystem>
int main() {
bool created_new_directory = false;
bool there_was_an_exception = false;

try {
      = std::filesystem::create_directory("directory_name");
} catch(std::exception & e){
there_was_an_exception = true;
// creation failed
if ((not created_new_directory) and (not there_was_an_exception)) {
    // no failure, but the directory was already present.

Best Regards,

1 Like