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.SetFormat(HPS::Image::Format::Png);
	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 {
  created_new_directory
      = 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,
Simon

1 Like