Provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of std::fstream objects.
Public Static Methods | |
template<typename type_t > | |
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, this method creates a file, writes the specified lines to the file, and then closes the file. | |
template<typename type_t > | |
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, this method creates a file, writes the specified lines to the file, and then closes the file. | |
template<typename type_t > | |
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, this method creates a file, writes the specified lines to the file, and then closes the file. | |
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) |
Copies an existing file to a new file. Overwriting a file of the same name is not allowed. | |
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::ofstream | create (const xtd::string &path) |
Creates or overwrites a file in the specified path. | |
static std::ofstream | create_text (const xtd::string &path) |
Creates or opens a file for writing text. | |
static bool | exists (const xtd::string &path) noexcept |
Determines whether the specified file exists. | |
static xtd::io::file_attributes | get_attributes (const xtd::string &path) |
Gets the xtd::io::file_attributes of the file on the path. | |
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 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 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) |
Moves a specified file to a new location, providing the option to specify a new file name. | |
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 overwrite the destination file if it already exists. | |
static std::fstream | open (const xtd::string &path, std::ios::openmode mode) |
Opens a FileStream on the specified path. | |
static std::ifstream | open_read (const xtd::string &path) |
Opens an existing file for reading. | |
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 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. | |
template<typename char_t > | |
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. | |
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 void | remove (const xtd::string &path) |
Deletes the specified file. | |
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 file, and creating a backup of the replaced file and optionally ignores merge errors. | |
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 void | set_creation_time (const xtd::string &path, const xtd::date_time &creation_time) |
Sets the date and time the file was created. | |
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 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. | |
template<typename type_t > | |
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, this method creates a file, writes the specified lines to the file, and then closes the file. | |
template<typename type_t > | |
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, this method creates a file, writes the specified lines to the file, and then closes the file. | |
template<typename type_t > | |
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, this method creates a file, writes the specified lines to the file, and then closes the file. | |
static std::ofstream | write_text (const xtd::string &path) |
Creates a std::ofstream that appends text to an existing file. | |
|
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.
path | The file to write to. |
contents | The lines to append to the file. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
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.
path | The file to write to. |
contents | The lines to append to the file. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
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.
path | The file to write to. |
contents | The text to append to the file. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Creates a std::ofstream that appends text to an existing file.
path | The path to the file to append to. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Copies an existing file to a new file. Overwriting a file of the same name is not allowed.
src | The file to be opened for reading. |
dest | The name of the destination file. This cannot be a directory or an existing file. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::file_not_found_exception | if file src does not exists. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Copies an existing file to a new file. Overwriting a file of the same name is allowed.
src | The file to be opened for reading. |
dest | The name of the destination file. This cannot be a directory. |
overwrite | true if the destination file can be overwritten; otherwise, false. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path -or- file dest exists. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Creates or overwrites a file in the specified path.
The | path and name of the file to create. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path -or- file dest exists. |
xtd::io::io_exception | the handle of the specified file cannot be created. |
|
static |
Creates or opens a file for writing text.
Creates or overwrites a file in the specified path.
The | path and name of the file to create. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path -or- file dest exists. |
xtd::io::io_exception | the handle of the specified file cannot be created. |
|
staticnoexcept |
Determines whether the specified file exists.
path | The file to check. |
|
static |
Gets the xtd::io::file_attributes of the file on the path.
path | The path to the file. |
xtd::io::file_not_found_exception | if file src does not exists. |
|
static |
Returns the creation date and time of the specified file or directory.
path | The file or directory for which to obtain creation date and time information. |
xtd::unauthorized_access_exception | The caller does not have the required permission. |
xtd::argument_exception | path 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_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::not_supported_excpttion | path is in an invalid format. |
|
static |
Returns the date and time the specified file or directory was last accessed.
path | The file or directory for which to obtain access date and time information. |
xtd::unauthorized_access_exception | The caller does not have the required permission. |
xtd::argument_exception | path 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_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::not_supported_excpttion | path is in an invalid format. |
|
static |
Returns the date and time the specified file or directory was last written to.
path | The file or directory for which to obtain write date and time information. |
xtd::unauthorized_access_exception | The caller does not have the required permission. |
xtd::argument_exception | path 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_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::not_supported_excpttion | path is in an invalid format. |
|
static |
Gets the xtd::io::file_permissions of the file on the path.
path | The path to the file. |
xtd::io::file_not_found_exception | if file src does not exists. |
|
static |
Moves a specified file to a new location, providing the option to specify a new file name.
src | The name of the file to move. |
dest | The new path for the file. |
xtd::argument_exception | if dest already exist. |
xtd::io::io_exception | if path is empty or an invalid path. |
xtd::io::io_exception | if the caller has not the required permissions. |
|
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.
src | The name of the file to move. |
dest | The new path for the file. |
overwrite | true to overwrite the destination file if it already exists; false otherwise. |
xtd::argument_exception | if dest already exist. |
xtd::io::io_exception | if path is empty or an invalid path. |
xtd::io::io_exception | if the caller has not the required permissions. |
|
static |
Opens a FileStream on the specified path.
path | The file to open. |
mode | A 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. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Opens an existing file for reading.
path | The file to be opened for reading. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Opens an existing file for reading.
path | The file to be opened for reading. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Opens an existing file for writing.
path | The file to be opened for writing. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
path | The file to open for reading. |
xtd::io::file_not_found_exception | if path does not exists. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
inlinestatic |
Opens a binary file, reads the contents of the file into a byte array, and then closes the file.
path | The file to open for reading. |
xtd::io::file_not_found_exception | if path does not exists. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Opens a text file, reads all lines of the file, and then closes the file.
path | The file to open for reading. |
|
static |
Opens a text file, reads all text of the file, and then closes the file.
path | The file to open for reading. |
|
static |
Deletes the specified file.
path | The name of the file to be deleted. |
|
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.
source_file_name | The name of a file that replaces the file specified by destination_file_name. |
destination_file_name | The name of the file being replaced. |
destination_backup_file_name | The name of the backup file. |
ignore_metadata_errors | true to ignore merge errors (such as attributes and access control lists (ACLs)) from the replaced file to the replacement file; otherwise, false. |
|
static |
Sets the specified xtd::io::file_attributes of the file on the specified path.
path | The path to the file. |
attributes | A bitwise combination of the enumeration values. |
xtd::io::io_exception | The file specified by path is a directory. |
xtd::argument_exception | path 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_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::io::file_not_found_exception | The specified path is invalid (for example, it is on an unmapped drive). |
xtd::not_supported_exception | path 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. |
|
static |
Sets the date and time the file was created.
path | The file for which to set the creation date and time information. |
creation_time | A xtd::date_time containing the value to set for the creation date and time of path. This value is expressed in local time. |
xtd::io::io_exception | The file specified by path is a directory. |
xtd::argument_exception | path 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_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::io::file_not_found_exception | The specified path is invalid (for example, it is on an unmapped drive). |
xtd::not_supported_exception | path 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. |
|
static |
Sets the date and time the specified file was last accessed.
path | The file for which to set the access date and time information. |
last_access_time | A xtd::date_time containing the value to set for the last access date and time of path. This value is expressed in local |
xtd::io::io_exception | The file specified by path is a directory. |
xtd::argument_exception | path 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_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::io::file_not_found_exception | The specified path is invalid (for example, it is on an unmapped drive). |
xtd::not_supported_exception | path 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. |
|
static |
Sets the date and time that the specified file was last written to.
path | The file for which to set the date and time information. |
last_write_time | A xtd::date_time containing the value to set for the last write date and time of path. This value is expressed in local time. |
xtd::io::io_exception | The file specified by path is a directory. |
xtd::argument_exception | path 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_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::io::file_not_found_exception | The specified path is invalid (for example, it is on an unmapped drive). |
xtd::not_supported_exception | path 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. |
|
static |
Sets the specified xtd::io::file_permissions of the file on the specified path.
path | The path to the file. |
attributes | A bitwise combination of the enumeration values. |
xtd::io::io_exception | The file specified by path is a directory. |
xtd::argument_exception | path 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_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::io::file_not_found_exception | The specified path is invalid (for example, it is on an unmapped drive). |
xtd::not_supported_exception | path 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. |
|
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.
path | The file to write to. |
contents | The lines to write to the file. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
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.
path | The file to write to. |
contents | The lines to write to the file. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
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.
path | The file to write to. |
contents | The text to write to the file. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |
|
static |
Creates a std::ofstream that appends text to an existing file.
path | The path to the file to write to. |
xtd::argument_exception | path contains one or more of the invalid characters -or- The system could not retrieve the absolute path. |
xtd::io::io_exception | the handle of the specified file cannot be opened. |