Provides static methods for the creation, copying, deletion, moving, and opening of files, and aids in the creation of std::fstream objects.
Public Fields | |
static const file_info | empty |
Represents the uninitialized xtd::io::file_info object. This field is constant. | |
Public Constructors | |
file_info (const xtd::string &file_name) | |
Initializes a new instance of the xtd::io::file_info class, which acts as a wrapper for a file path. | |
Public Properties | |
xtd::io::directory_info | directory () const |
Gets an instance of the parent directory. | |
xtd::string | directory_name () const |
Gets a string representing the directory's full path. | |
bool | exists () const override |
Gets a value indicating whether a file exists. | |
bool | is_read_only () const |
Gets a value that determines if the current file is read only. | |
void | is_read_only (bool value) |
Sets a value that determines if the current file is read only. | |
size_t | length () const |
Gets the size, in bytes, of the current file. | |
xtd::string | name () const override |
Gets the name of the file. | |
Public Methods | |
xtd::io::stream_writer | append_text () const |
Creates a xtd::io::stream_writer that appends text to the file represented by this instance of the xtd::io::file_info. | |
xtd::io::file_info | copy_to (const xtd::string &dest_file_name) const |
Copies an existing file to a new file, disallowing the overwriting of an existing file. | |
xtd::io::file_info | copy_to (const xtd::string &dest_file_name, bool overwrite) const |
Copies an existing file to a new file, allowing the overwriting of an existing file. | |
std::ofstream | create () const |
Creates a file. | |
xtd::io::stream_writer | create_text () const |
Creates a std::ofstream that writes a new text file. | |
void | move_to (const xtd::string &dest_file_name) |
Moves a specified file to a new location, providing the option to specify a new file name. | |
void | move_to (const xtd::string &dest_file_name, 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. | |
std::fstream | open (std::ios::openmode mode) const |
Opens a file in the specified mode. | |
std::ifstream | open_read () const |
Creates a read-only std::ifstream. | |
xtd::io::stream_reader | open_text () const |
Creates a xtd::io::stream_reader that reads from an existing text file. | |
std::ofstream | open_write () const |
Creates a write-only std::ofstream. | |
void | remove () const override |
Permanently deletes a file. | |
file_info | replace (const xtd::string &destination_file_name, const xtd::string &destination_backup_file_name) |
Replaces the contents of a specified file with the file described by the current xtd::io::file_info object, deleting the original file, and creating a backup of the replaced file. | |
Additional Inherited Members | |
Public Member Functions inherited from xtd::io::file_system_info | |
xtd::io::file_attributes | attributes () const |
Gets the attributes for the current file or directory. | |
xtd::io::file_system_info & | attributes (xtd::io::file_attributes value) |
Sets the attributes for the current file or directory. | |
const xtd::date_time & | creation_time () const |
Gets the creation time of the current file or directory. | |
xtd::io::file_system_info & | creation_time (const xtd::date_time &value) |
Gets the creation time of the current file or directory. | |
xtd::date_time | creation_time_utc () const |
Gets the creation time, in coordinated universal time (UTC), of the current file or directory. | |
xtd::io::file_system_info & | creation_time_utc (const xtd::date_time &value) |
Sets the creation time, in coordinated universal time (UTC), of the current file or directory. | |
virtual xtd::string | extension () const |
Gets the extension part of the file name, including the leading dot . even if it is the entire file name, or an empty string if no extension is present. | |
xtd::string | full_name () const |
Gets the full path of the directory or file. | |
const xtd::date_time & | last_access_time () const |
Gets the time the current file or directory was last accessed. | |
xtd::io::file_system_info & | last_access_time (const xtd::date_time &value) |
Sets the time the current file or directory was last accessed. | |
xtd::date_time | last_access_time_utc () const |
Gets the time, in coordinated universal time (UTC), that the current file or directory was last accessed. | |
xtd::io::file_system_info & | last_access_time_utc (const xtd::date_time &value) |
Sets the time, in coordinated universal time (UTC), that the current file or directory was last accessed. | |
const xtd::date_time & | last_write_time () const |
Gets the time when the current file or directory was last written to. | |
xtd::io::file_system_info & | last_write_time (const xtd::date_time &value) |
Sets the time when the current file or directory was last written to. | |
xtd::date_time | last_write_time_utc () const |
Gets the time, in coordinated universal time (UTC), when the current file or directory was last written to. | |
xtd::io::file_system_info & | last_write_time_utc (const xtd::date_time &value) |
Sets the time, in coordinated universal time (UTC), when the current file or directory was last written to. | |
xtd::io::file_permissions | permissions () const |
Gets the permissions for the current file or directory. | |
xtd::io::file_system_info & | permissions (xtd::io::file_permissions value) |
Sets the permissions for the current file or directory. | |
void | refresh () |
Refreshes the state of the object. | |
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::name properties for the full path or file/directory name. | |
Public Member Functions inherited from xtd::object | |
object ()=default | |
Create a new instance of the ultimate base class object. | |
virtual bool | equals (const object &obj) const noexcept |
Determines whether the specified object is equal to the current object. | |
virtual size_t | get_hash_code () const noexcept |
Serves as a hash function for a particular type. | |
virtual type_object | get_type () const noexcept |
Gets the type of the current instance. | |
template<typename object_t > | |
xtd::uptr< object_t > | memberwise_clone () const |
Creates a shallow copy of the current object. | |
Static Public Member Functions inherited from xtd::object | |
template<typename object_a_t , typename object_b_t > | |
static bool | equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
Determines whether the specified object instances are considered equal. | |
template<typename object_a_t , typename object_b_t > | |
static bool | reference_equals (const object_a_t &object_a, const object_b_t &object_b) noexcept |
Determines whether the specified object instances are the same instance. | |
Protected Attributes inherited from xtd::io::file_system_info | |
xtd::string | full_path_ |
Represents the fully qualified path of the directory or file. | |
xtd::string | original_path_ |
The path originally specified by the user, whether relative or absolute. | |
Protected Member Functions inherited from xtd::io::file_system_info | |
file_system_info ()=default | |
Initializes a new instance of the xtd::io::file_system_info class. | |
Protected Member Functions inherited from xtd::abstract_object | |
abstract_object ()=default | |
Initializes a new instance of the xtd::abstract_object class. | |
|
explicit |
Initializes a new instance of the xtd::io::file_info class, which acts as a wrapper for a file path.
file_name | The fully qualified name of the new file, or the relative file name. Do not end the path with the directory separator character. |
xtd:argument_exception | The file name is empty, contains only white spaces, or contains invalid characters. |
xtd::security::security_exception | The caller does not have the required permission. |
xtd::unauthorized_access_exception | Access to fileName is denied. |
xtd::io::path_too_long_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::not_supported_exception | fileName contains a colon (:) in the middle of the string. |
xtd::io::directory_info xtd::io::file_info::directory | ( | ) | const |
Gets an instance of the parent directory.
xtd::io::directory_not_found_exception | The specified path is invalid, such as being on an unmapped drive. |
xtd::security::security_exception | The caller does not have the required permission. |
xtd::string xtd::io::file_info::directory_name | ( | ) | const |
Gets a string representing the directory's full path.
xtd::security::security_exception | The caller does not have the required permission. |
xtd::io::path_too_long_exception | The specified path, file name, or both exceed the system-defined maximum length. |
|
overridevirtual |
Gets a value indicating whether a file exists.
Implements xtd::io::file_system_info.
bool xtd::io::file_info::is_read_only | ( | ) | const |
Gets a value that determines if the current file is read only.
xtd::io::file_not_found_exception | The file described by the current xtd::io::file_info object could not be found. |
xtd::io::io_exception | An I/O error occurred while opening the file. |
xtd::unauthorized_access_exception | This operation is not supported on the current platform. -or- The caller does not have the required permission. |
xtd::argument_exception | The user does not have write permission, but attempted to set this property to false. |
void xtd::io::file_info::is_read_only | ( | bool | value | ) |
Sets a value that determines if the current file is read only.
value | true if the current file is read only; otherwise, false. |
xtd::io::file_not_found_exception | The file described by the current xtd::io::file_info object could not be found. |
xtd::io::io_exception | An I/O error occurred while opening the file. |
xtd::unauthorized_access_exception | This operation is not supported on the current platform. -or- The caller does not have the required permission. |
xtd::argument_exception | The user does not have write permission, but attempted to set this property to false. |
size_t xtd::io::file_info::length | ( | ) | const |
Gets the size, in bytes, of the current file.
xtd::io::io_exception | xtd::io::file_info::refresh cannot update the state of the file or directory. |
xtd::io::file_not_found_exception | The file does not exist. -or- The xtd::io::file_info::size property is called for a directory. |
|
overridevirtual |
Gets the name of the file.
Implements xtd::io::file_system_info.
xtd::io::stream_writer xtd::io::file_info::append_text | ( | ) | const |
Creates a xtd::io::stream_writer that appends text to the file represented by this instance of the xtd::io::file_info.
xtd::io::file_info xtd::io::file_info::copy_to | ( | const xtd::string & | dest_file_name | ) | const |
Copies an existing file to a new file, disallowing the overwriting of an existing file.
desy_file_name | The name of the new file to copy to. |
xtd::argument_exception | dest_file_name is empty, contains only white spaces, or contains invalid characters. |
xtd::io_io_exception | An error occurs, or the destination file already exists and overwrite is false. |
xtd::security::security_exception | The caller does not have the required permission. |
xtd::io::directory_not_found_exception | The directory specified in dest_file_name does not exist. |
xtd::unauthorized_access_exceptionA | directory path is passed in, or the file is being moved to a different drive. |
xtd::ioo::path_too_long_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::not_supported_exception | dest_file_name contains a colon (:) in the middle of the string. |
xtd::io::file_info xtd::io::file_info::copy_to | ( | const xtd::string & | dest_file_name, |
bool | overwrite | ||
) | const |
Copies an existing file to a new file, allowing the overwriting of an existing file.
dest_file_name | The name of the new file to copy to. |
overwrite | true to allow an existing file to be overwritten; otherwise, false. |
xtd::argument_exception | dest_file_name is empty, contains only white spaces, or contains invalid characters. |
xtd::io_io_exception | An error occurs, or the destination file already exists and overwrite is false. |
xtd::security::security_exception | The caller does not have the required permission. |
xtd::io::directory_not_found_exception | The directory specified in dest_file_name does not exist. |
xtd::unauthorized_access_exceptionA | directory path is passed in, or the file is being moved to a different drive. |
xtd::ioo::path_too_long_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::not_supported_exception | dest_file_name contains a colon (:) in the middle of the string. |
std::ofstream xtd::io::file_info::create | ( | ) | const |
Creates a file.
xtd::io::stream_writer xtd::io::file_info::create_text | ( | ) | const |
Creates a std::ofstream that writes a new text file.
xtd::unauthorized_access_exception | The file name is a directory. |
xtd::io::io_exception | The disk is read-only. |
xtd::security::security_exception | The caller does not have the required permission. |
void xtd::io::file_info::move_to | ( | const xtd::string & | dest_file_name | ) |
Moves a specified file to a new location, providing the option to specify a new file name.
dest_file_name | The path to move the file to, which can specify a different file name. |
xtd::io::io_exception | An I/O error occurs, such as the destination file already exists or the destination device is not ready. |
xtd::argument_exception | dest_file_name is empty, contains only white spaces, or contains invalid characters. |
xtd::security::security_exception | The caller does not have the required permission. |
xtd::unauthorized_access_exception | dest_file_name is read-only or is a directory. |
xtd::io::file_not_found_exception | The file is not found. |
xtd::io::directory_not_found_exception | The specified path is invalid, such as being on an unmapped drive. |
xtd::io::path_too_long_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::not_supported_exception | dest_file_name contains a colon (:) in the middle of the string. |
void xtd::io::file_info::move_to | ( | const xtd::string & | dest_file_name, |
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.
dest_file_name | The path to move the file to, which can specify a different file name. |
overwrite | true to overwrite the destination file if it already exists; false otherwise. |
xtd::io::io_exception | An I/O error occurred, such as the destination device is not ready. |
xtd::argument_exception | dest_file_name is empty, contains only white spaces, or contains invalid characters. |
xtd::security::security_exception | The caller does not have the required permission. |
xtd::unauthorized_access_exception | dest_file_name is read-only or is a directory. |
xtd::io::file_not_found_exception | The file is not found. |
xtd::io::directory_not_found_exception | The specified path is invalid, such as being on an unmapped drive. |
xtd::io::path_too_long_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::not_supported_exception | dest_file_name contains a colon (:) in the middle of the string. |
std::fstream xtd::io::file_info::open | ( | std::ios::openmode | mode | ) | const |
Opens a file in the specified mode.
mode | A std::ios::openmode constant specifying the mode (for example, std::ios::openmode::in or std::ios::openmode::app) in which to open the file. |
xtd::io::file_not_found_exception | The file is not found. |
xtd::unauthorized_access_exception | The file is read-only or is a directory. |
xtd::io::directory_not_found_exception | The specified path is invalid, such as being on an unmapped drive. |
xtd::io::io_exception | The file is already open. |
std::ifstream xtd::io::file_info::open_read | ( | ) | const |
Creates a read-only std::ifstream.
xtd::unauthorized_access_exception | name is read-only or is a directory. |
xtd::io::directory_not_found_exception | The specified path is invalid, such as being on an unmapped drive. |
xtd::io::io_exception | The file is already open. |
xtd::io::stream_reader xtd::io::file_info::open_text | ( | ) | const |
Creates a xtd::io::stream_reader that reads from an existing text file.
xtd::security::security_exception | The caller does not have the required permission. |
xtd::io::file_not_found_exception | The file is not found. |
xtd::unauthorized_access_exception | name is read-only or is a directory. |
xtd::io::directory_not_found_exception | The specified path is invalid, such as being on an unmapped drive. |
std::ofstream xtd::io::file_info::open_write | ( | ) | const |
Creates a write-only std::ofstream.
xtd::unauthorized_access_exception | The path specified when creating an instance of the xtd::io::file_info object is read-only or is a directory. |
xtd::io::directory_not_found_exception | The path specified when creating an instance of the xtd::io::file_info object is invalid, such as being on an unmapped drive. |
|
overridevirtual |
Permanently deletes a file.
xtd::io::io_exception | The target file is open or memory-mapped on a computer running Microsoft Windows NT. -or- There is an open handle on the file, and the operating system is Windows XP or earlier. This open handle can result from enumerating directories and files. For more information, see How to: Enumerate Directories and Files. |
xtd::security::security_exception | The caller does not have the required permission. |
xtd::unauthorized_access_exception | The path is a directory. |
Implements xtd::io::file_system_info.
file_info xtd::io::file_info::replace | ( | const xtd::string & | destination_file_name, |
const xtd::string & | destination_backup_file_name | ||
) |
Replaces the contents of a specified file with the file described by the current xtd::io::file_info object, deleting the original file, and creating a backup of the replaced file.
destination_file_name | The name of a file to replace with the current file. |
destination_backup_file_name | The name of a file with which to create a backup of the file described by the destFileName parameter. |
xtd::argument_exception | The path described by the destFileName parameter was not of a legal form. -or- The path described by the destBackupFileName parameter was not of a legal form. |
xtd::io::file_not_found_exception | The file described by the current xtd::io::file_info object could not be found. -or- The file described by the destinationFileName parameter could not be found. |
xtd::platform_not_supported_exception | The current operating system is not Microsoft Windows NT or later. |
|
static |
Represents the uninitialized xtd::io::file_info object. This field is constant.