Show how to use xtd::io::file_info::replace method.
#include <xtd/xtd>
class program {
public:
static auto main() {
try {
auto original_file = "test.txt"_s;
auto file_to_replace = "test2.txt"_s;
auto backup_of_file_to_replace = "test2.txt.bak"_s;
if (file::exists(original_file) && file::exists(file_to_replace)) {
console::write_line("Move the contents of " + original_file + " into " + file_to_replace + ", delete " + original_file + ", and create a backup of " + file_to_replace + ".");
replace_file(original_file, file_to_replace, backup_of_file_to_replace);
console::write_line("Done");
} else
console::write_line("Either the file {0} or {1} doesn't exist.", original_file, file_to_replace);
} catch (const system_exception& e) {
console::write_line(e.message());
}
console::read_key();
}
static void replace_file(const string& file_to_move_and_delete, const string& file_to_replace, const string& backup_of_file_to_replace) {
auto f_info = file_info {file_to_move_and_delete};
f_info.replace(file_to_replace, backup_of_file_to_replace);
}
};
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.hpp:168