xtd 0.2.0
Loading...
Searching...
No Matches
xtd::io::file Class Reference
Inheritance diagram for xtd::io::file:
xtd::static_object

Definition

Provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of std::fstream objects.

Provides static methods for the creation, copying, deletion, moving, and opening of files,...
Definition file.hpp:39
#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
Inheritance
xtd::static_objectxtd::io::file
Header
#include <xtd/io/file>
Namespace
xtd::io
Library
xtd.core

Public Static Methods

template<class type_t>
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, this method creates a file, writes the specified lines to the file, and then closes the file.
 
template<class type_t>
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, this method creates a file, writes the specified lines to the file, and then closes the file.
 
template<class type_t>
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, this method creates a file, writes the specified lines to the file, and then closes the file.
 
static auto append_text (const xtd::string &path) -> std::ofstream
 Creates a std::ofstream that appends text to an existing file.
 
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 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 create (const xtd::string &path) -> std::ofstream
 Creates or overwrites a file in the specified path.
 
static auto create_text (const xtd::string &path) -> xtd::io::stream_writer
 Creates or opens a file for writing text.
 
static auto exists (const xtd::string &path) noexcept -> bool
 Determines whether the specified file exists.
 
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 get_creation_time (const xtd::string &path) -> xtd::date_time
 Returns the creation date and time of the specified file or directory.
 
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 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 get_permissions (const xtd::string &path) -> xtd::io::file_permissions
 Gets the xtd::io::file_permissions of the file on the path.
 
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 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 overwrite the destination file if it already exists.
 
static auto open (const xtd::string &path, std::ios::openmode mode) -> std::fstream
 Opens a FileStream on the specified path.
 
static auto open_read (const xtd::string &path) -> std::ifstream
 Opens an existing file for reading.
 
static auto open_text (const xtd::string &path) -> xtd::io::stream_reader
 Opens an existing file for reading.
 
static auto open_write (const xtd::string &path) -> std::ofstream
 Opens an existing file for writing.
 
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.
 
template<class char_t>
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.
 
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 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 remove (const xtd::string &path) -> void
 Deletes the specified file.
 
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 file, and creating a backup of the replaced file and optionally ignores merge errors.
 
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 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_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 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 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.
 
template<class type_t>
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, this method creates a file, writes the specified lines to the file, and then closes the file.
 
template<class type_t>
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, this method creates a file, writes the specified lines to the file, and then closes the file.
 
template<class type_t>
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, this method creates a file, writes the specified lines to the file, and then closes the file.
 
static auto write_text (const xtd::string &path) -> xtd::io::stream_writer
 Creates a std::ofstream that appends text to an existing file.
 

Member Function Documentation

◆ append_all_lines() [1/2]

template<class type_t>
static auto xtd::io::file::append_all_lines ( const xtd::string & path,
type_t contents ) -> void
inlinestatic

Appends lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
pathThe file to write to.
contentsThe lines to append to the file.
Returns
true if the text appended; otherwise, false.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.
Remarks
If the target file already exists, it is overwritten.

◆ append_all_lines() [2/2]

template<class type_t>
static auto xtd::io::file::append_all_lines ( const xtd::string & path,
const std::initializer_list< type_t > & contents ) -> void
inlinestatic

Appends lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
pathThe file to write to.
contentsThe lines to append to the file.
Returns
true if the text appended; otherwise, false.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.
Remarks
If the target file already exists, it is overwritten.

◆ append_all_text()

template<class type_t>
static auto xtd::io::file::append_all_text ( const xtd::string & path,
type_t text ) -> void
inlinestatic

Appends text to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
pathThe file to write to.
contentsThe text to append to the file.
Returns
true if the text appended; otherwise, false.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ append_text()

static auto xtd::io::file::append_text ( const xtd::string & path) -> std::ofstream
staticnodiscard

Creates a std::ofstream that appends text to an existing file.

Parameters
pathThe path to the file to append to.
Returns
A std::ofstream that appends text to an existing file.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ copy() [1/2]

static auto xtd::io::file::copy ( const xtd::string & src,
const xtd::string & dest ) -> void
static

Copies an existing file to a new file. Overwriting a file of the same name is not allowed.

Parameters
srcThe file to be opened for reading.
destThe name of the destination file. This cannot be a directory or an existing file.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::file_not_found_exceptionif file src does not exists.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ copy() [2/2]

static auto xtd::io::file::copy ( const xtd::string & src,
const xtd::string & dest,
bool overwrite ) -> void
static

Copies an existing file to a new file. Overwriting a file of the same name is allowed.

Parameters
srcThe file to be opened for reading.
destThe name of the destination file. This cannot be a directory.
overwritetrue if the destination file can be overwritten; otherwise, false.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path
-or-
file dest exists.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ create()

static auto xtd::io::file::create ( const xtd::string & path) -> std::ofstream
staticnodiscard

Creates or overwrites a file in the specified path.

Parameters
Thepath and name of the file to create.
Returns
A std::ofstream that provides read/write access to the file specified in path.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path
-or-
file dest exists.
xtd::io::io_exceptionthe handle of the specified file cannot be created.

◆ create_text()

static auto xtd::io::file::create_text ( const xtd::string & path) -> xtd::io::stream_writer
staticnodiscard

Creates or opens a file for writing text.

Creates or overwrites a file in the specified path.

Parameters
Thepath and name of the file to create.
Returns
A std::ofstream that provides read/write access to the file specified in path.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path
-or-
file dest exists.
xtd::io::io_exceptionthe handle of the specified file cannot be created.

◆ exists()

static auto xtd::io::file::exists ( const xtd::string & path) -> bool
staticnodiscardnoexcept

Determines whether the specified file exists.

Parameters
pathThe file to check.
Returns
true if the caller has the required permissions and path contains the name of an existing file; otherwise, false.
Remarks
This method also returns false if path is empty or an invalid path.
If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.

◆ get_attributes()

static auto xtd::io::file::get_attributes ( const xtd::string & path) -> xtd::io::file_attributes
staticnodiscard

Gets the xtd::io::file_attributes of the file on the path.

Parameters
pathThe path to the file.
Returns
The xtd::io::file_attributes of the file on the path.
Exceptions
xtd::io::file_not_found_exceptionif file src does not exists.

◆ get_creation_time()

static auto xtd::io::file::get_creation_time ( const xtd::string & path) -> xtd::date_time
staticnodiscard

Returns the creation date and time of the specified file or directory.

Parameters
pathThe file or directory for which to obtain creation date and time information.
Returns
A xtd::date_time class set to the creation date and time for the specified file or directory. This value is expressed in local time.
Exceptions
xtd::unauthorized_access_exceptionThe caller does not have the required permission.
xtd::argument_exceptionpath is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::path::get_invalid_path_chars method.
xtd::io::path_too_long_exceptionThe specified path, file name, or both exceed the system-defined maximum length.
xtd::not_supported_excpttionpath is in an invalid format.

◆ get_last_access_time()

static auto xtd::io::file::get_last_access_time ( const xtd::string & path) -> xtd::date_time
staticnodiscard

Returns the date and time the specified file or directory was last accessed.

Parameters
pathThe file or directory for which to obtain access date and time information.
Returns
A xtd::date_time structure set to the date and time that the specified file or directory was last accessed. This value is expressed in local time.
Exceptions
xtd::unauthorized_access_exceptionThe caller does not have the required permission.
xtd::argument_exceptionpath is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::path::get_invalid_path_chars method.
xtd::io::path_too_long_exceptionThe specified path, file name, or both exceed the system-defined maximum length.
xtd::not_supported_excpttionpath is in an invalid format.

◆ get_last_write_time()

static auto xtd::io::file::get_last_write_time ( const xtd::string & path) -> xtd::date_time
staticnodiscard

Returns the date and time the specified file or directory was last written to.

Parameters
pathThe file or directory for which to obtain write date and time information.
Returns
A xtd::date_time structure set to the date and time that the specified file or directory was last written to. This value is expressed in local time.
Exceptions
xtd::unauthorized_access_exceptionThe caller does not have the required permission.
xtd::argument_exceptionpath is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::path::get_invalid_path_chars method.
xtd::io::path_too_long_exceptionThe specified path, file name, or both exceed the system-defined maximum length.
xtd::not_supported_excpttionpath is in an invalid format.

◆ get_permissions()

static auto xtd::io::file::get_permissions ( const xtd::string & path) -> xtd::io::file_permissions
staticnodiscard

Gets the xtd::io::file_permissions of the file on the path.

Parameters
pathThe path to the file.
Returns
The xtd::io::file_permissions of the file on the path.
Exceptions
xtd::io::file_not_found_exceptionif file src does not exists.

◆ move() [1/2]

static auto xtd::io::file::move ( const xtd::string & src,
const xtd::string & dest ) -> void
static

Moves a specified file to a new location, providing the option to specify a new file name.

Parameters
srcThe name of the file to move.
destThe new path for the file.
Returns
true if the file moved; otherwise, false.
Exceptions
xtd::argument_exceptionif dest already exist.
xtd::io::io_exceptionif path is empty or an invalid path.
xtd::io::io_exceptionif the caller has not the required permissions.

◆ move() [2/2]

static auto xtd::io::file::move ( const xtd::string & src,
const xtd::string & dest,
bool overwrite ) -> void
static

Moves a specified file to a new location, providing the options to specify a new file name and to overwrite the destination file if it already exists.

Parameters
srcThe name of the file to move.
destThe new path for the file.
overwritetrue to overwrite the destination file if it already exists; false otherwise.
Returns
true if the file moved; otherwise, false.
Exceptions
xtd::argument_exceptionif dest already exist.
xtd::io::io_exceptionif path is empty or an invalid path.
xtd::io::io_exceptionif the caller has not the required permissions.

◆ open()

static auto xtd::io::file::open ( const xtd::string & path,
std::ios::openmode mode ) -> std::fstream
staticnodiscard

Opens a FileStream on the specified path.

Parameters
pathThe file to open.
modeA std::ios::openmode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.
Returns
A std::fstream on the specified path.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ open_read()

static auto xtd::io::file::open_read ( const xtd::string & path) -> std::ifstream
staticnodiscard

Opens an existing file for reading.

Parameters
pathThe file to be opened for reading.
Returns
A std::ifstream on the specified path.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ open_text()

static auto xtd::io::file::open_text ( const xtd::string & path) -> xtd::io::stream_reader
staticnodiscard

Opens an existing file for reading.

Parameters
pathThe file to be opened for reading.
Returns
A std::ifstream on the specified path.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ open_write()

static auto xtd::io::file::open_write ( const xtd::string & path) -> std::ofstream
staticnodiscard

Opens an existing file for writing.

Parameters
pathThe file to be opened for writing.
Returns
A std::ofstream on the specified path.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ read_all_bytes() [1/2]

static auto xtd::io::file::read_all_bytes ( const xtd::string & path) -> xtd::array< xtd::byte >
staticnodiscard

Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

Parameters
pathThe file to open for reading.
Returns
A byte array containing the contents of the file.
Exceptions
xtd::io::file_not_found_exceptionif path does not exists.
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ read_all_bytes() [2/2]

template<class char_t>
static auto xtd::io::file::read_all_bytes ( const char_t * path) -> xtd::array<xtd::byte>
inlinestaticnodiscard

Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

Parameters
pathThe file to open for reading.
Returns
A byte array containing the contents of the file.
Exceptions
xtd::io::file_not_found_exceptionif path does not exists.
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ read_all_lines()

static auto xtd::io::file::read_all_lines ( const xtd::string & path) -> xtd::array< xtd::string >
staticnodiscard

Opens a text file, reads all lines of the file, and then closes the file.

Parameters
pathThe file to open for reading.
Returns
A String array containing all lines of the file.
Remarks
This method also returns an empty array if path is empty or an invalid path.
If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns an empty array regardless of the existence of path.

◆ read_all_text()

static auto xtd::io::file::read_all_text ( const xtd::string & path) -> xtd::string
staticnodiscard

Opens a text file, reads all text of the file, and then closes the file.

Parameters
pathThe file to open for reading.
Returns
A string containing all text of the file.
Remarks
This method also returns empty string if path is empty or an invalid path.
If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns empty string regardless of the existence of file.

◆ remove()

static auto xtd::io::file::remove ( const xtd::string & path) -> void
static

Deletes the specified file.

Parameters
pathThe name of the file to be deleted.
Returns
std::ofstream An unshared std::ofstream that provides access to the specified file, with the specified mode and access.
true if the file is deleted; otherwise, false.

◆ replace()

static auto xtd::io::file::replace ( const xtd::string & source_file_name,
const xtd::string & destination_file_name,
const xtd::string & destination_backup_file_name ) -> void
static

Replaces the contents of a specified file with the contents of another file, deleting the original file, and creating a backup of the replaced file and optionally ignores merge errors.

Parameters
source_file_nameThe name of a file that replaces the file specified by destination_file_name.
destination_file_nameThe name of the file being replaced.
destination_backup_file_nameThe name of the backup file.
ignore_metadata_errorstrue to ignore merge errors (such as attributes and access control lists (ACLs)) from the replaced file to the replacement file; otherwise, false.
Returns
false source_file_name does not exist or bad format, or destination_file_name does not exist or bad format, or if ignore_metadata_errors equal false and destination_backup_file_name bad format or on ani io error; otherwise true.

◆ set_attributes()

static auto xtd::io::file::set_attributes ( const xtd::string & path,
xtd::io::file_attributes attributes ) -> void
static

Sets the specified xtd::io::file_attributes of the file on the specified path.

Parameters
pathThe path to the file.
attributesA bitwise combination of the enumeration values.
Exceptions
xtd::io::io_exceptionThe file specified by path is a directory.
xtd::argument_exceptionpath is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method.
xtd::io::path_too_long_exceptionThe specified path, file name, or both exceed the system-defined maximum length.
xtd::io::file_not_found_exceptionThe specified path is invalid (for example, it is on an unmapped drive).
xtd::not_supported_exceptionpath contains a colon character (:) that is not part of a drive label ("C:\"). @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks Certain file attributes, such as xtd::io::file_attributes::hidden and xtd::io::file_attributes::read_only, can be combined. Other attributes, such as xtd::io::file_attributes::normal, must be used alone. @remarks It is not possible to change the compression status of a xtd::io::file object using the xtd::io::file::set_attributes method. @remarks For a list of common I/O tasks, see <a href="https://gammasoft71.github.io/xtd/docs/documentation/guides/xtd.core/Common%20I%3AO%20tasks" >Common I/O Tasks.

◆ set_creation_time()

static auto xtd::io::file::set_creation_time ( const xtd::string & path,
const xtd::date_time & creation_time ) -> void
static

Sets the date and time the file was created.

Parameters
pathThe file for which to set the creation date and time information.
creation_timeA xtd::date_time containing the value to set for the creation date and time of path. This value is expressed in local time.
Exceptions
xtd::io::io_exceptionThe file specified by path is a directory.
xtd::argument_exceptionpath is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method.
xtd::io::path_too_long_exceptionThe specified path, file name, or both exceed the system-defined maximum length.
xtd::io::file_not_found_exceptionThe specified path is invalid (for example, it is on an unmapped drive).
xtd::not_supported_exceptionpath contains a colon character (:) that is not part of a drive label ("C:\"). @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks NTFS-formatted drives may cache file meta-info, such as file creation time, for a short period of time. As a result, it may be necessary to explicitly set the creation time of a file if you are overwriting or replacing an existing file. @remarks For a list of common I/O tasks, see <a href="https://gammasoft71.github.io/xtd/docs/documentation/guides/xtd.core/Common%20I%3AO%20tasks" >Common I/O Tasks.

◆ set_last_access_time()

static auto xtd::io::file::set_last_access_time ( const xtd::string & path,
const xtd::date_time & last_access_time ) -> void
static

Sets the date and time the specified file was last accessed.

Parameters
pathThe file for which to set the access date and time information.
last_access_timeA xtd::date_time containing the value to set for the last access date and time of path. This value is expressed in local
Exceptions
xtd::io::io_exceptionThe file specified by path is a directory.
xtd::argument_exceptionpath is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method.
xtd::io::path_too_long_exceptionThe specified path, file name, or both exceed the system-defined maximum length.
xtd::io::file_not_found_exceptionThe specified path is invalid (for example, it is on an unmapped drive).
xtd::not_supported_exceptionpath contains a colon character (:) that is not part of a drive label ("C:\"). @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks For a list of common I/O tasks, see <a href="https://gammasoft71.github.io/xtd/docs/documentation/guides/xtd.core/Common%20I%3AO%20tasks" >Common I/O Tasks.

◆ set_last_write_time()

static auto xtd::io::file::set_last_write_time ( const xtd::string & path,
const xtd::date_time & last_write_time ) -> void
static

Sets the date and time that the specified file was last written to.

Parameters
pathThe file for which to set the date and time information.
last_write_timeA xtd::date_time containing the value to set for the last write date and time of path. This value is expressed in local time.
Exceptions
xtd::io::io_exceptionThe file specified by path is a directory.
xtd::argument_exceptionpath is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method.
xtd::io::path_too_long_exceptionThe specified path, file name, or both exceed the system-defined maximum length.
xtd::io::file_not_found_exceptionThe specified path is invalid (for example, it is on an unmapped drive).
xtd::not_supported_exceptionpath contains a colon character (:) that is not part of a drive label ("C:\"). @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks For a list of common I/O tasks, see <a href="https://gammasoft71.github.io/xtd/docs/documentation/guides/xtd.core/Common%20I%3AO%20tasks" >Common I/O Tasks.

◆ set_permissions()

static auto xtd::io::file::set_permissions ( const xtd::string & path,
xtd::io::file_permissions permissions ) -> void
static

Sets the specified xtd::io::file_permissions of the file on the specified path.

Parameters
pathThe path to the file.
attributesA bitwise combination of the enumeration values.
Exceptions
xtd::io::io_exceptionThe file specified by path is a directory.
xtd::argument_exceptionpath is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters by using the xtd::io::path::get_invalid_path_chars method.
xtd::io::path_too_long_exceptionThe specified path, file name, or both exceed the system-defined maximum length.
xtd::io::file_not_found_exceptionThe specified path is invalid (for example, it is on an unmapped drive).
xtd::not_supported_exceptionpath contains a colon character (:) that is not part of a drive label ("C:\"). @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks For a list of common I/O tasks, see <a href="https://gammasoft71.github.io/xtd/docs/documentation/guides/xtd.core/Common%20I%3AO%20tasks" >Common I/O Tasks.

◆ write_all_lines() [1/2]

template<class type_t>
static auto xtd::io::file::write_all_lines ( const xtd::string & path,
type_t contents ) -> void
inlinestatic

Writes lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
pathThe file to write to.
contentsThe lines to write to the file.
Returns
true if the text written; otherwise, false.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.
Remarks
If the target file already exists, it is overwritten.

◆ write_all_lines() [2/2]

template<class type_t>
static auto xtd::io::file::write_all_lines ( const xtd::string & path,
const std::initializer_list< type_t > & contents ) -> void
inlinestatic

Writes lines to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
pathThe file to write to.
contentsThe lines to write to the file.
Returns
true if the text written; otherwise, false.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.
Remarks
If the target file already exists, it is overwritten.

◆ write_all_text()

template<class type_t>
static auto xtd::io::file::write_all_text ( const xtd::string & path,
type_t text ) -> void
inlinestatic

Writes text to a file, and then closes the file. If the specified file does not exist, this method creates a file, writes the specified lines to the file, and then closes the file.

Parameters
pathThe file to write to.
contentsThe text to write to the file.
Returns
true if the text written; otherwise, false.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

◆ write_text()

static auto xtd::io::file::write_text ( const xtd::string & path) -> xtd::io::stream_writer
staticnodiscard

Creates a std::ofstream that appends text to an existing file.

Parameters
pathThe path to the file to write to.
Returns
A std::ofstream that writes text to an existing file.
Exceptions
xtd::argument_exceptionpath contains one or more of the invalid characters
-or-
The system could not retrieve the absolute path.
xtd::io::io_exceptionthe handle of the specified file cannot be opened.

The documentation for this class was generated from the following file: