#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;
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);
} else
console::write_line(
"Either the file {0} or {1} doesn't exist.", original_file, file_to_replace);
}
}
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);
}
};
static console_key_info read_key()
Obtains the next character or function key pressed by the user. The pressed key is displayed in the c...
static void write_line()
Writes the current line terminator to the standard output stream using the specified format informati...
Provides static methods for the creation, copying, deletion, moving, and opening of files,...
Definition file_info.hpp:41
file_info replace(const xtd::string &destination_file_name, const xtd::string &destination_backup_file_name)
Replaces the contents of a specified file with the file described by the current xtd::io::file_info o...
static bool exists(const xtd::string &path) noexcept
Determines whether the specified file exists.
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:167
@ e
The E key.
Definition console_key.hpp:96
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:17
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8