Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to perform boost::filesystem copy_file with overwrite

The Windows API function CopyFile has an argument BOOL bFailIfExists that allows you to control whether or not you want to overwrite the target file if it exists.

The boost::filesystem copy_file function has no such argument, and will fail if the target file exists. Is there an elegant way to use the boost copy_file function and overwrite the target file? Or is it better to simply use the Windows API? My current target platform is Windows, but I prefer to use STL and boost where possible to keep my code platform independent.

Thank you.

like image 642
Dani van der Meer Avatar asked May 06 '09 13:05

Dani van der Meer


1 Answers

There's a third enum argument to copy_file, boost::filesystem::copy_option::overwrite_if_exists

copy_file(source_path, destination_path, copy_option::overwrite_if_exists); 

https://www.boost.org/doc/libs/1_75_0/libs/filesystem/doc/reference.html

like image 197
anno Avatar answered Sep 22 '22 06:09

anno