xtd 0.2.0
Loading...
Searching...
No Matches
file.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "file_attributes.hpp"
7#include "stream_reader.hpp"
8#include "stream_writer.hpp"
9#include "../array.hpp"
10#include "../chrono.hpp"
11#include "../core_export.hpp"
12#include "../date_time.hpp"
13#include "../static.hpp"
14#include "../string.hpp"
15#include <cstdint>
16#include <cstdio>
17#include <fstream>
18#include <tuple>
19
21namespace xtd {
23 namespace io {
40 public:
42
51 template<class type_t>
52 static auto append_all_lines(const xtd::string& path, type_t contents) -> void {
54 for (const auto& line : contents)
55 sw.write_line(line);
56 }
57
65 template<class type_t>
66 static auto append_all_lines(const xtd::string& path, const std::initializer_list<type_t>& contents) -> void {
68 for (const auto& line : contents)
69 sw.write_line(line);
70 }
71
78 template<class type_t>
79 static auto append_all_text(const xtd::string& path, type_t text) -> void {
81 sw.write(text);
82 }
83
89 [[nodiscard]] static auto append_text(const xtd::string& path) -> std::ofstream;
90
97 static auto copy(const xtd::string& src, const xtd::string& dest) -> void;
98
105 static auto copy(const xtd::string& src, const xtd::string& dest, bool overwrite) -> void;
106
112 [[nodiscard]] static auto create(const xtd::string& path) -> std::ofstream;
113
120 [[nodiscard]] static auto create_text(const xtd::string& path) -> xtd::io::stream_writer;
121
127 [[nodiscard]] static auto exists(const xtd::string& path) noexcept -> bool;
128
133 [[nodiscard]] static auto get_attributes(const xtd::string& path) -> xtd::io::file_attributes;
134
142 [[nodiscard]] static auto get_creation_time(const xtd::string& path) -> xtd::date_time;
143
151 [[nodiscard]] static auto get_last_access_time(const xtd::string& path) -> xtd::date_time;
152
160 [[nodiscard]] static auto get_last_write_time(const xtd::string& path) -> xtd::date_time;
161
166 [[nodiscard]] static auto get_permissions(const xtd::string& path) -> xtd::io::file_permissions;
167
175 static auto move(const xtd::string& src, const xtd::string& dest) -> void;
176
185 static auto move(const xtd::string& src, const xtd::string& dest, bool overwrite) -> void;
186
193 [[nodiscard]] static auto open(const xtd::string& path, std::ios::openmode mode) -> std::fstream;
194
200 [[nodiscard]] static auto open_read(const xtd::string& path) -> std::ifstream;
201
207 [[nodiscard]] static auto open_text(const xtd::string& path) -> xtd::io::stream_reader;
208
214 [[nodiscard]] static auto open_write(const xtd::string& path) -> std::ofstream;
215
222 [[nodiscard]] static auto read_all_bytes(const xtd::string& path) -> xtd::array<xtd::byte>;
223
230 template<class char_t>
231 [[nodiscard]] static auto read_all_bytes(const char_t* path) -> xtd::array<xtd::byte> {return read_all_bytes(xtd::string(path));}
232
238 [[nodiscard]] static auto read_all_lines(const xtd::string& path) -> xtd::array<xtd::string>;
239
245 [[nodiscard]] static auto read_all_text(const xtd::string& path) -> xtd::string;
246
251 static auto remove(const xtd::string& path) -> void;
252
259 static auto replace(const xtd::string& source_file_name, const xtd::string& destination_file_name, const xtd::string& destination_backup_file_name) -> void;
260
273 static auto set_attributes(const xtd::string& path, xtd::io::file_attributes attributes) -> void;
274
286 static auto set_creation_time(const xtd::string& path, const xtd::date_time& creation_time) -> void;
287
298 static auto set_last_access_time(const xtd::string& path, const xtd::date_time& last_access_time) -> void;
299
310 static auto set_last_write_time(const xtd::string& path, const xtd::date_time& last_write_time) -> void;
311
322 static auto set_permissions(const xtd::string& path, xtd::io::file_permissions permissions) -> void;
323
331 template<class type_t>
332 static auto write_all_lines(const xtd::string& path, type_t contents) -> void {
334 for (const auto& line : contents)
335 sw.write_line(line);
336 }
337
345 template<class type_t>
346 static auto write_all_lines(const xtd::string& path, const std::initializer_list<type_t>& contents) -> void {
348 for (const auto& line : contents)
349 sw.write_line(line);
350 }
351
358 template<class type_t>
359 static auto write_all_text(const xtd::string& path, type_t text) -> void {
361 sw.write(text);
362 }
363
369 [[nodiscard]] static auto write_text(const xtd::string& path) -> xtd::io::stream_writer;
371 private:
372 [[nodiscard]] static auto get_file_times(const string& path) -> std::tuple<std::time_t, std::time_t, std::time_t>;
373 };
374 }
375}
Contains xtd::array class.
Contains std::chrono::days, std::chrono::weeks, std::chrono::months and std::chrono::years duration t...
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition array.hpp:64
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.hpp:83
Provides static methods for the creation, copying, deletion, moving, and opening of files,...
Definition file.hpp:39
static auto open(const xtd::string &path, std::ios::openmode mode) -> std::fstream
Opens a FileStream on the specified path.
static auto open_write(const xtd::string &path) -> std::ofstream
Opens an existing file for writing.
static auto append_all_lines(const xtd::string &path, const std::initializer_list< type_t > &contents) -> void
Appends lines to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:66
static auto write_all_lines(const xtd::string &path, const std::initializer_list< type_t > &contents) -> void
Writes lines to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:346
static auto write_all_lines(const xtd::string &path, type_t contents) -> void
Writes lines to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:332
static auto exists(const xtd::string &path) noexcept -> bool
Determines whether the specified file exists.
static auto copy(const xtd::string &src, const xtd::string &dest, bool overwrite) -> void
Copies an existing file to a new file. Overwriting a file of the same name is allowed.
static auto open_read(const xtd::string &path) -> std::ifstream
Opens an existing file for reading.
static auto create(const xtd::string &path) -> std::ofstream
Creates or overwrites a file in the specified path.
static auto read_all_lines(const xtd::string &path) -> xtd::array< xtd::string >
Opens a text file, reads all lines of the file, and then closes the file.
static auto get_last_access_time(const xtd::string &path) -> xtd::date_time
Returns the date and time the specified file or directory was last accessed.
static auto write_all_text(const xtd::string &path, type_t text) -> void
Writes text to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:359
static auto get_permissions(const xtd::string &path) -> xtd::io::file_permissions
Gets the xtd::io::file_permissions of the file on the path.
static auto get_last_write_time(const xtd::string &path) -> xtd::date_time
Returns the date and time the specified file or directory was last written to.
static auto create_text(const xtd::string &path) -> xtd::io::stream_writer
Creates or opens a file for writing text.
static auto set_permissions(const xtd::string &path, xtd::io::file_permissions permissions) -> void
Sets the specified xtd::io::file_permissions of the file on the specified path.
static auto replace(const xtd::string &source_file_name, const xtd::string &destination_file_name, const xtd::string &destination_backup_file_name) -> void
Replaces the contents of a specified file with the contents of another file, deleting the original fi...
static auto append_text(const xtd::string &path) -> std::ofstream
Creates a std::ofstream that appends text to an existing file.
static auto append_all_text(const xtd::string &path, type_t text) -> void
Appends text to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:79
static auto write_text(const xtd::string &path) -> xtd::io::stream_writer
Creates a std::ofstream that appends text to an existing file.
static auto read_all_text(const xtd::string &path) -> xtd::string
Opens a text file, reads all text of the file, and then closes the file.
static auto set_last_access_time(const xtd::string &path, const xtd::date_time &last_access_time) -> void
Sets the date and time the specified file was last accessed.
static auto copy(const xtd::string &src, const xtd::string &dest) -> void
Copies an existing file to a new file. Overwriting a file of the same name is not allowed.
static auto set_last_write_time(const xtd::string &path, const xtd::date_time &last_write_time) -> void
Sets the date and time that the specified file was last written to.
static auto append_all_lines(const xtd::string &path, type_t contents) -> void
Appends lines to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:52
static auto move(const xtd::string &src, const xtd::string &dest) -> void
Moves a specified file to a new location, providing the option to specify a new file name.
static auto set_creation_time(const xtd::string &path, const xtd::date_time &creation_time) -> void
Sets the date and time the file was created.
static auto set_attributes(const xtd::string &path, xtd::io::file_attributes attributes) -> void
Sets the specified xtd::io::file_attributes of the file on the specified path.
static auto read_all_bytes(const xtd::string &path) -> xtd::array< xtd::byte >
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
static auto get_attributes(const xtd::string &path) -> xtd::io::file_attributes
Gets the xtd::io::file_attributes of the file on the path.
static auto open_text(const xtd::string &path) -> xtd::io::stream_reader
Opens an existing file for reading.
static auto remove(const xtd::string &path) -> void
Deletes the specified file.
static auto move(const xtd::string &src, const xtd::string &dest, bool overwrite) -> void
Moves a specified file to a new location, providing the options to specify a new file name and to ove...
static auto read_all_bytes(const char_t *path) -> xtd::array< xtd::byte >
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
Definition file.hpp:231
static auto get_creation_time(const xtd::string &path) -> xtd::date_time
Returns the creation date and time of the specified file or directory.
Performs operations on std::basic_string instances that contain file or directory path information....
Definition path.hpp:37
Implements a xtd::io::text_reader that reads characters from a byte stream.
Definition stream_reader.hpp:28
Implements a xtd::io::text_writer for writing characters to a stream.
Definition stream_writer.hpp:28
auto write(const xtd::string &value) -> void override
Writes the specified string value to the text stream.
auto write_line() -> void
Writes new line to the text stream.
Contains core_export_ keyword.
Contains xtd::date_time class.
Contains xtd::io::file_attributes enum class.
Contains xtd::io::file_permissions enum class.
#define static_
This keyword is use to represent a static object. A static object can't be instantiated (constructors...
Definition static.hpp:37
#define core_export_
Define shared library export.
Definition core_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
file_attributes
Provides attributes for files and directories.
Definition file_attributes.hpp:24
file_permissions
Provides permissions for files and directories.
Definition file_permissions.hpp:24
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.hpp:17
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:17
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
Contains xtd::static_object class.
Contains xtd::io::stream_reader class.
Contains xtd::io::stream_writer class.
Contains xtd::string alias.