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 "../chrono.hpp"
10#include "../core_export.hpp"
11#include "../date_time.hpp"
12#include "../static.hpp"
13#include "../string.hpp"
14#include <cstdint>
15#include <cstdio>
16#include <fstream>
17#include <tuple>
18#include <vector>
19
21namespace xtd {
23 namespace io {
40 public:
42
51 template<typename type_t>
52 static void append_all_lines(const xtd::string& path, type_t contents) {
54 for (const auto& line : contents)
55 sw.write_line(line);
56 }
57
65 template<typename type_t>
66 static void append_all_lines(const xtd::string& path, const std::initializer_list<type_t>& contents) {
68 for (const auto& line : contents)
69 sw.write_line(line);
70 }
71
78 template<typename type_t>
79 static void append_all_text(const xtd::string& path, type_t text) {
81 sw.write(text);
82 }
83
89 static std::ofstream append_text(const xtd::string& path);
90
97 static void copy(const xtd::string& src, const xtd::string& dest);
98
105 static void copy(const xtd::string& src, const xtd::string& dest, bool overwrite);
106
112 static std::ofstream create(const xtd::string& path);
113
120 static std::ofstream create_text(const xtd::string& path);
121
127 static bool exists(const xtd::string& path) noexcept;
128
134
143
152
161
167
175 static void move(const xtd::string& src, const xtd::string& dest);
176
185 static void move(const xtd::string& src, const xtd::string& dest, bool overwrite);
186
193 static std::fstream open(const xtd::string& path, std::ios::openmode mode);
194
200 static std::ifstream open_read(const xtd::string& path);
201
207 static std::ifstream open_text(const xtd::string& path);
208
214 static std::ofstream open_write(const xtd::string& path);
215
222 static std::vector<xtd::byte> read_all_bytes(const xtd::string& path);
223
230 template<typename char_t>
231 static std::vector<xtd::byte> read_all_bytes(const char_t* path) {return read_all_bytes(xtd::string(path));}
232
238 static std::vector<xtd::string> read_all_lines(const xtd::string& path);
239
246
251 static void remove(const xtd::string& path);
252
259 static void replace(const xtd::string& source_file_name, const xtd::string& destination_file_name, const xtd::string& destination_backup_file_name);
260
274
286 static void set_creation_time(const xtd::string& path, const xtd::date_time& creation_time);
287
298 static void set_last_access_time(const xtd::string& path, const xtd::date_time& last_access_time);
299
310 static void set_last_write_time(const xtd::string& path, const xtd::date_time& last_write_time);
311
323
331 template<typename type_t>
332 static void write_all_lines(const xtd::string& path, type_t contents) {
334 for (const auto& line : contents)
335 sw.write_line(line);
336 }
337
345 template<typename type_t>
346 static void write_all_lines(const xtd::string& path, const std::initializer_list<type_t>& contents) {
348 for (const auto& line : contents)
349 sw.write_line(line);
350 }
351
358 template<typename type_t>
359 static void write_all_text(const xtd::string& path, type_t text) {
361 sw.write(text);
362 }
363
369 static std::ofstream write_text(const xtd::string& path);
371 private:
372 static std::tuple<time_t, time_t, time_t> get_file_times(const string& path);
373 };
374 }
375}
Represents text as a sequence of character units.
Definition basic_string.hpp:79
Represents an instant in time, typically expressed as a date and time of day.
Definition date_time.hpp:85
Provides static methods for the creation, copying, deletion, moving, and opening of files,...
Definition file.hpp:39
static std::ofstream append_text(const xtd::string &path)
Creates a std::ofstream that appends text to an existing file.
static void copy(const xtd::string &src, const xtd::string &dest, bool overwrite)
Copies an existing file to a new file. Overwriting a file of the same name is allowed.
static std::vector< xtd::byte > read_all_bytes(const char_t *path)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
Definition file.hpp:231
static void append_all_lines(const xtd::string &path, type_t contents)
Appends lines to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:52
static void append_all_text(const xtd::string &path, type_t text)
Appends text to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:79
static void write_all_lines(const xtd::string &path, type_t contents)
Writes lines to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:332
static std::ofstream create(const xtd::string &path)
Creates or overwrites a file in the specified path.
static void replace(const xtd::string &source_file_name, const xtd::string &destination_file_name, const xtd::string &destination_backup_file_name)
Replaces the contents of a specified file with the contents of another file, deleting the original fi...
static std::ifstream open_text(const xtd::string &path)
Opens an existing file for reading.
static std::ofstream open_write(const xtd::string &path)
Opens an existing file for writing.
static void set_attributes(const xtd::string &path, xtd::io::file_attributes attributes)
Sets the specified xtd::io::file_attributes of the file on the specified path.
static std::ofstream write_text(const xtd::string &path)
Creates a std::ofstream that appends text to an existing file.
static xtd::date_time get_last_write_time(const xtd::string &path)
Returns the date and time the specified file or directory was last written to.
static void set_creation_time(const xtd::string &path, const xtd::date_time &creation_time)
Sets the date and time the file was created.
static std::vector< xtd::byte > read_all_bytes(const xtd::string &path)
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
static std::ifstream open_read(const xtd::string &path)
Opens an existing file for reading.
static void append_all_lines(const xtd::string &path, const std::initializer_list< type_t > &contents)
Appends lines to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:66
static void move(const xtd::string &src, const xtd::string &dest)
Moves a specified file to a new location, providing the option to specify a new file name.
static void write_all_lines(const xtd::string &path, const std::initializer_list< type_t > &contents)
Writes lines to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:346
static void copy(const xtd::string &src, const xtd::string &dest)
Copies an existing file to a new file. Overwriting a file of the same name is not allowed.
static void set_last_access_time(const xtd::string &path, const xtd::date_time &last_access_time)
Sets the date and time the specified file was last accessed.
static std::ofstream create_text(const xtd::string &path)
Creates or opens a file for writing text.
static xtd::date_time get_creation_time(const xtd::string &path)
Returns the creation date and time of the specified file or directory.
static xtd::date_time get_last_access_time(const xtd::string &path)
Returns the date and time the specified file or directory was last accessed.
static std::vector< xtd::string > read_all_lines(const xtd::string &path)
Opens a text file, reads all lines of the file, and then closes the file.
static xtd::string read_all_text(const xtd::string &path)
Opens a text file, reads all text of the file, and then closes the file.
static xtd::io::file_permissions get_permissions(const xtd::string &path)
Gets the xtd::io::file_permissions of the file on the path.
static void move(const xtd::string &src, const xtd::string &dest, bool overwrite)
Moves a specified file to a new location, providing the options to specify a new file name and to ove...
static void remove(const xtd::string &path)
Deletes the specified file.
static xtd::io::file_attributes get_attributes(const xtd::string &path)
Gets the xtd::io::file_attributes of the file on the path.
static void set_last_write_time(const xtd::string &path, const xtd::date_time &last_write_time)
Sets the date and time that the specified file was last written to.
static void set_permissions(const xtd::string &path, xtd::io::file_permissions permissions)
Sets the specified xtd::io::file_permissions of the file on the specified path.
static std::fstream open(const xtd::string &path, std::ios::openmode mode)
Opens a FileStream on the specified path.
static void write_all_text(const xtd::string &path, type_t text)
Writes text to a file, and then closes the file. If the specified file does not exist,...
Definition file.hpp:359
static bool exists(const xtd::string &path) noexcept
Determines whether the specified file exists.
Performs operations on std::basic_string instances that contain file or directory path information....
Definition path.hpp:36
Implements a xtd::io::text_writer for writing characters to a stream.
Definition stream_writer.hpp:28
void write(const xtd::string &value) override
Writes the specified string value to the text stream.
void write_line()
Writes new line to the text stream.
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
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 namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10
Contains xtd::io::stream_reader class.
Contains xtd::io::stream_writer class.