I've written a basic function which uses the std::filesystem
to just copy all contents in a directory recursively to another directory. The code worked at first, but now broke out of nowhere and throws the following error when executing:
generic:2
My code:
#include <filesystem>
#include <string>
#include <iostream>
namespace fs = std::filesystem;
class backup {
private:
fs::path location;
public:
backup(std::string location_str) {
location = fs::path(location_str);
}
std::error_code fetch_files(std::string src_str) {
std::error_code err;
fs::path src(src_str);
fs::copy_options copy_opts = fs::copy_options::recursive | fs::copy_options::overwrite_existing | fs::copy_options::copy_symlinks;
fs::copy(src, location, copy_opts, err);
return err;
}
int main(int argc, char* argv[]) {
backup example_backup("~/Desktop/backup_destination");
std::cout << backup.fetch_files("~/Desktop/backup_source") << std::endl;
return 0;
}