xtd 0.2.0
Loading...
Searching...
No Matches

◆ last_write_time() [1/2]

const xtd::date_time & xtd::io::file_system_info::last_write_time ( ) const

Gets the time when the current file or directory was last written to.

Returns
The time the current file was last written.
Exceptions
xtd::io::io_exceptionsystem error when retrieving the file information.
xtd::io::directory_not_found_exceptionThe specified path is invalid; for example, it is on an unmapped drive.
xtd::platform_not_supported_exceptionThe opration is not supported on the current operating system.
Examples
The following code example demonstrates the updating of the xtd::io::file_system_info::last_write_time property through a "touch" operation. In this example, the file is "touched", updating the xtd::io::file_system_info::creation_time, xtd::io::file_system_info::last_access_time and xtd::io::file_system_info::last_write_time properties to the current date and time.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::io;
class touch {
public:
static auto main(const std::vector<string>& args) {
// Make sure a filename was provided.
if (args.size() > 0) {
// Verify that the provided filename exists.
if (file::exists(args[0])) {
file_info fi(args[0]);
touch_file(fi);
} else {
console::write_line("Could not find the file: {0}.", args[0]);
}
} else {
console::write_line("No file was specified.");
}
}
static void touch_file(file_system_info& fsi) {
console::write_line("Touching: {0}", fsi.full_name());
// Update the CreationTime, LastWriteTime and LastAccessTime.
try {
auto now = date_time::now();
fsi.creation_time(now).last_write_time(now).last_access_time(now);
} catch (const exception& e) {
console::write_line("Error: {0}", e.message());
}
}
};
startup_(touch::main);
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.h:26
Provides static methods for the creation, copying, deletion, moving, and opening of files,...
Definition file_info.h:41
const xtd::date_time & creation_time() const
Gets the creation time of the current file or directory.
xtd::string full_name() const
Gets the full path of the directory or file.
Provides the base class for both xtd::io::file_info and xtd::io::directory_info objects.
Definition file_system_info.h:87
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
@ e
The E key.
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.h:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Note
This method may return an inaccurate value because it uses native functions whose values may not be continuously updated by the operating system.
Remarks
The value of the xtd::io::file_system_info::last_write_time property is pre-cached if the current instance of the xtd::io::file_system_info object was returned from any of the following xtd::io::directory_info methods:
Examples
file_info2.cpp, and file_info_move_to.cpp.