2NinerRomeo
2NinerRomeo

Reputation: 2827

Is there a cross-platform version of win32 CopyFile?

If I need to, I suppose I could write my own version using streams, but this seems like a basic piece of functionality which should be out there somewhere.

Upvotes: 0

Views: 472

Answers (3)

2NinerRomeo
2NinerRomeo

Reputation: 2827

The boost::filesystem library contains a copy_file function. It is documented at the boost website.

It can be used like this

#include <string>
#include <boost/filesystem.hpp>

std::string sourcePath = "./sourceFile.txt";
std::string destPath  = "./destFile.txt";
boost::filesystem::copy_file(sourcePath, destPath, boost::filesystem::copy_option::overwrite_if_exists);

Upvotes: 3

mr_kazz
mr_kazz

Reputation: 101

2NinerRomeo's post contains an error: it should say overwrite_if_exists whare it says overwrite_if_exitsts

Upvotes: 0

rob05c
rob05c

Reputation: 1233

There are cross platform libraries with that functionality, such as boost and Poco.

Upvotes: 2

Related Questions