#include <xtd/io/file>
#include <xtd/io/file_info>
#include <xtd/console>
#include <xtd/startup>
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);
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);
}
};
basic_string replace(value_type old_char, value_type new_char) const noexcept
Replaces all occurrences of a specified char_t in this basic_string with another specified char_t.
Definition basic_string.hpp:1647
Provides static methods for the creation, copying, deletion, moving, and opening of files,...
Definition file_info.hpp:41
The exception that is thrown when a method call is invalid for the object's current state.
Definition system_exception.hpp:18
#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:175
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10