xtd 0.2.0
Loading...
Searching...
No Matches
file_info2.cpp

Show how to use xtd::io::file_info class.

#include <xtd/io/file>
#include <xtd/io/file_info>
#include <xtd/io/path>
#include <xtd/console>
using namespace xtd;
using namespace xtd::io;
auto main() -> int {
auto test_file = path::combine(path::get_temp_path(), "test_file.txt");
file::write_all_text(test_file, "Hello, World!");
file_info fi(test_file);
console::write_line("full_name = {}", fi.full_name());
console::write_line(" attributes = {}", fi.attributes());
console::write_line(" creation_time = {}", fi.creation_time());
console::write_line(" exists = {}", fi.exists());
console::write_line(" extension = {}", fi.extension());
console::write_line(" last_access_time = {}", fi.last_access_time());
console::write_line(" last_write_time = {}", fi.last_write_time());
console::write_line(" length = {}", fi.length());
console::write_line(" name = {}", fi.name());
console::write_line(" to_string = {}", fi.to_string());
file::remove(test_file);
}
// This code produces the following output :
//
// full_name = //var/folders/d5/k7mxnq214dxf3jbvvvhpbfqh0000gn/T/test_file.txt
// attributes = normal
// creation_time = Fri Oct 22 22:05:37 2021
// exists = true
// extension = .txt
// last_access_time = Fri Oct 22 22:05:37 2021
// last_write_time = Fri Oct 22 22:05:37 2021
// length = 13
// name = test_file.txt
// to_string = /var/folders/d5/k7mxnq214dxf3jbvvvhpbfqh0000gn/T/test_file.txt
Provides static methods for the creation, copying, deletion, moving, and opening of files,...
Definition file_info.hpp:41
bool exists() const override
Gets a value indicating whether a file exists.
size_t length() const
Gets the size, in bytes, of the current file.
xtd::string name() const override
Gets the name of the file.
const xtd::date_time & last_access_time() const
Gets the time the current file or directory was last accessed.
const xtd::date_time & creation_time() const
Gets the creation time of the current file or directory.
xtd::io::file_attributes attributes() const
Gets the attributes for the current file or directory.
xtd::string full_name() const
Gets the full path of the directory or file.
const xtd::date_time & last_write_time() const
Gets the time when the current file or directory was last written to.
xtd::string to_string() const noexcept override
Returns the original path. Use the xtd::io::file_system_info::full_name or xtd::io::file_system_info:...
virtual xtd::string extension() const
Gets the extension part of the file name, including the leading dot . even if it is the entire file n...
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