Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.
Classes | |
class | directory_iterator |
Represent directory iterator used by xtd::io::directory_info. More... | |
class | file_iterator |
Represent file iterator used by xtd::io::directory_info. More... | |
class | file_system_info_iterator |
Represent file system iterator used by xtd::io::directory_info. More... | |
Public Fields | |
static const directory_info | empty |
Represents the uninitialized xtd::io::directory_info object. This field is constant. | |
Public Constructors | |
directory_info (const xtd::string &path) | |
Initializes a new instance of the xtd::io::directory_info class on the specified path. | |
Properrties | |
bool | exists () const override |
Gets a value indicating whether the directory exists. | |
xtd::string | name () const override |
Gets the name of this xtd::io::directory_info instance. | |
xtd::io::directory_info | parent () const |
Gets the parent directory of a specified subdirectory. | |
xtd::io::directory_info | root () const |
Gets the root portion of the directory. | |
Public Methods | |
void | create () |
Creates a directory. | |
xtd::io::directory_info | create_subdirectory (const xtd::string &path) const |
Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the xtd::io::directory_info class. | |
xtd::io::directory_info::directory_iterator | enumerate_directories () const |
Returns an enumerable collection of directory information in the current directory. | |
xtd::io::directory_info::directory_iterator | enumerate_directories (const xtd::string &search_pattern) const |
Returns an enumerable collection of directory information that matches a specified search pattern. | |
xtd::io::directory_info::file_iterator | enumerate_files () const |
Returns an enumerable collection of file information in the current directory. | |
xtd::io::directory_info::file_iterator | enumerate_files (const xtd::string &search_pattern) const |
Returns an enumerable collection of file information that matches a search pattern. | |
xtd::io::directory_info::file_system_info_iterator | enumerate_file_system_infos () const |
Returns an enumerable collection of file system information in the current directory. | |
xtd::io::directory_info::file_system_info_iterator | enumerate_file_system_infos (const xtd::string &search_pattern) const |
Returns an enumerable collection of file system information that matches a specified search pattern. | |
std::vector< xtd::io::directory_info > | get_directories () const |
Returns the subdirectories of the current directory. | |
std::vector< xtd::io::directory_info > | get_directories (const xtd::string &search_pattern) const |
Returns an array of directories in the current DirectoryInfo matching the given search criteria. | |
std::vector< xtd::io::file_info > | get_files () const |
Returns a file list from the current directory. | |
std::vector< xtd::io::file_info > | get_files (const xtd::string &search_pattern) const |
Returns a file list from the current directory matching the given search pattern. | |
std::vector< xtd::sptr< xtd::io::file_system_info > > | get_file_system_infos () const |
Returns an array of strongly typed xtd::io::file_system_info entries representing all the files and subdirectories in a directory. | |
std::vector< xtd::sptr< xtd::io::file_system_info > > | get_file_system_infos (const xtd::string &search_pattern) const |
Retrieves an array of strongly typed FileSystemInfo objects representing the files and subdirectories that match the specified search criteria. | |
void | move_to (const xtd::string &dest_dir_name) |
Moves a DirectoryInfo instance and its contents to a new path. | |
void | remove () const override |
Deletes this xtd::io::directory_info if it is empty. | |
void | remove (bool recursive) const |
Deletes this instance of a DirectoryInfo, specifying whether to delete subdirectories and files. | |
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::directory_info class on the specified path.
path | A string specifying the path on which to create the xtd::io::directory_info. |
xtd::security::security_exception | The caller does not have the required permission. |
xtd::argument_exception | path contains invalid characters such as ", <, >, or |. @exception xtd::io::path_too_long_exception The specified path, file name, or both exceed the system-defined maximum length. @par Examples The following example uses this constructor to create the specified directory and subdirectory, and demonstrates that a directory that contains subdirectories cannot be deleted. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; class program { public: static auto main() { // Specify the directories you want to manipulate. directory_info di1(R"(c:\MyDir)"); directory_info di2(R"(c:\MyDir\temp)"); try { // Create the directories. di1.create(); di2.create(); // This operation will not be allowed because there are subdirectories. console::write_line("I am about to attempt to delete {0}.", di1.name()); di1.remove(); console::write_line("The delete operation was successful, which was unexpected."); } catch (const exception&) { console::write_line("The delete operation failed as expected."); } } }; startup_(program::main); @endicode @remarks This constructor does not check if a directory exists. This constructor is a placeholder for a string that is used to access the disk in subsequent operations. @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. |
|
overridevirtual |
Gets a value indicating whether the directory exists.
Implements xtd::io::file_system_info.
|
overridevirtual |
Gets the name of this xtd::io::directory_info instance.
Implements xtd::io::file_system_info.
xtd::io::directory_info xtd::io::directory_info::parent | ( | ) | const |
Gets the parent directory of a specified subdirectory.
xtd::security::security_exception | The caller does not have the required permission. |
xtd::io::directory_info xtd::io::directory_info::root | ( | ) | const |
Gets the root portion of the directory.
xtd::security::security_exception | The caller does not have the required permission. |
void xtd::io::directory_info::create | ( | ) |
Creates a directory.
xtd::io::io_exception | The directory cannot be created. |
xtd::io::directory_info xtd::io::directory_info::create_subdirectory | ( | const xtd::string & | path | ) | const |
Creates a subdirectory or subdirectories on the specified path. The specified path can be relative to this instance of the xtd::io::directory_info class.
path | The specified path. This cannot be a different disk volume or Universal Naming Convention (UNC) name. |
xtd::argument_exception | path does not specify a valid file path or contains invalid xtd::io::directory_info characters. |
xtd::io::directory_not_found_exception | The specified path is invalid, such as being on an unmapped drive. |
xtd::io::io_exception | The subdirectory cannot be created. -or- A file or directory already has the name specified by path. |
xtd::io::path_too_long_exception | The specified path, file name, or both exceed the system-defined maximum length. |
xtd::security::security_exception | The caller does not have code access permission to create the directory. |
xtd::not_supported_exception | path contains a colon character (:) that is not part of a drive label ("C:\"). @par Examples The following example demonstrates creating a subdirectory. In this example, the created directories are removed once created. Therefore, to test this sample, comment out the delete lines in the code. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; class program { public: static auto main() { // Create a reference to a directory. directory_info di("TempDir"); // Create the directory only if it does not already exist. if (di.exists() == false) di.create(); // Create a subdirectory in the directory just created. directory_info dis = di.create_subdirectory("SubDir"); // Process that directory as required. // ... // Delete the subdirectory. dis.remove(true); // Delete the directory. di.remove(true); } }; startup_(program::main); @endicode @remarks Any and all directories specified in path are created, unless some part of path is invalid. The path parameter specifies a directory path, not a file path. If the subdirectory already exists, this method does nothing. @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. |
xtd::io::directory_info::directory_iterator xtd::io::directory_info::enumerate_directories | ( | ) | const |
Returns an enumerable collection of directory information in the current 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 code access permission to create the directory. |
xtd::io::directory_info::directory_iterator xtd::io::directory_info::enumerate_directories | ( | const xtd::string & | search_pattern | ) | const |
Returns an enumerable collection of directory information that matches a specified search pattern.
search_pattern | The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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 code access permission to create the directory. |
Wildcard specifier | Matches |
---|---|
* (asterisk) | Zero or more characters in that position. |
? (question mark) | Zero or one character in that position. |
xtd::io::directory_info::file_iterator xtd::io::directory_info::enumerate_files | ( | ) | const |
Returns an enumerable collection of file information in the current 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 code access permission to create the directory. |
If you only need the names of the files, use the static xtd::io::directory class for better performance. For an example, see the xtd::io::directory::enumerate_files method.
xtd::io::directory_info::file_iterator xtd::io::directory_info::enumerate_files | ( | const xtd::string & | search_pattern | ) | const |
Returns an enumerable collection of file information that matches a search pattern.
search_pattern | The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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 code access permission to create the directory. |
Wildcard specifier | Matches |
---|---|
* (asterisk) | Zero or more characters in that position. |
? (question mark) | Zero or one character in that position. |
xtd::io::directory_info::file_system_info_iterator xtd::io::directory_info::enumerate_file_system_infos | ( | ) | const |
Returns an enumerable collection of file system information in the current 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 code access permission to create the directory. |
xtd::io::directory_info::file_system_info_iterator xtd::io::directory_info::enumerate_file_system_infos | ( | const xtd::string & | search_pattern | ) | const |
Returns an enumerable collection of file system information that matches a specified search pattern.
search_pattern | The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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 code access permission to create the directory. |
Wildcard specifier | Matches |
---|---|
* (asterisk) | Zero or more characters in that position. |
? (question mark) | Zero or one character in that position. |
std::vector< xtd::io::directory_info > xtd::io::directory_info::get_directories | ( | ) | const |
Returns the subdirectories of the current 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 code access permission to create the directory. |
std::vector< xtd::io::directory_info > xtd::io::directory_info::get_directories | ( | const xtd::string & | search_pattern | ) | const |
Returns an array of directories in the current DirectoryInfo matching the given search criteria.
search_pattern | The search string to match against the names of directories. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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 code access permission to create the directory. |
Wildcard specifier | Matches |
---|---|
* (asterisk) | Zero or more characters in that position. |
? (question mark) | Zero or one character in that position. |
std::vector< xtd::io::file_info > xtd::io::directory_info::get_files | ( | ) | const |
Returns a file list from the current 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 code access permission to create the directory. |
std::vector< xtd::io::file_info > xtd::io::directory_info::get_files | ( | const xtd::string & | search_pattern | ) | const |
Returns a file list from the current directory matching the given search pattern.
search_pattern | The search string to match against the names of files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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 code access permission to create the directory. |
Wildcard specifier | Matches |
---|---|
* (asterisk) | Zero or more characters in that position. |
? (question mark) | Zero or one character in that position. |
std::vector< xtd::sptr< xtd::io::file_system_info > > xtd::io::directory_info::get_file_system_infos | ( | ) | const |
Returns an array of strongly typed xtd::io::file_system_info entries representing all the files and subdirectories in a 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 code access permission to create the directory. |
std::vector< xtd::sptr< xtd::io::file_system_info > > xtd::io::directory_info::get_file_system_infos | ( | const xtd::string & | search_pattern | ) | const |
Retrieves an array of strongly typed FileSystemInfo objects representing the files and subdirectories that match the specified search criteria.
search_pattern | The search string to match against the names of directories and files. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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 code access permission to create the directory. |
Wildcard specifier | Matches |
---|---|
* (asterisk) | Zero or more characters in that position. |
? (question mark) | Zero or one character in that position. |
void xtd::io::directory_info::move_to | ( | const xtd::string & | dest_dir_name | ) |
Moves a DirectoryInfo instance and its contents to a new path.
dest_dir_name | The name and path to which to move this directory. The destination cannot be another disk volume or a directory with the identical name. It can be an existing directory to which you want to add this directory as a subdirectory. |
xtd::io::directory_not_found_exception | The specified path is invalid, such as being on an unmapped drive. |
xtd::io::io_exception | The directory is not empty. -or- The directory is the application's current working directory. -or- There is an open handle on the directory. |
xtd::security::security_exception | The caller does not have code access permission to create the directory. |
|
overridevirtual |
Deletes this xtd::io::directory_info if it is empty.
xtd::unauthorized_access_exception | The directory contains a read-only file. |
xtd::io::directory_not_found_exception | The directory described by this xtd::io::directory_info object does not exist or could not be found. |
xtd::io::io_exception | The directory is not empty. -or- The directory is the application's current working directory. -or- There is an open handle on the directory. |
xtd::security::security_exception | The caller does not have the required permission. |
Implements xtd::io::file_system_info.
void xtd::io::directory_info::remove | ( | bool | recursive | ) | const |
Deletes this instance of a DirectoryInfo, specifying whether to delete subdirectories and files.
recursive | true to delete this directory, its subdirectories, and all files; otherwise, false. |
xtd::unauthorized_access_exception | The directory contains a read-only file. |
xtd::io::directory_not_found_exception | The directory described by this xtd::io::directory_info object does not exist or could not be found. |
xtd::io::io_exception | The directory is not empty. -or- The directory is the application's current working directory. -or- There is an open handle on the directory. |
xtd::security::security_exception | The caller does not have the required permission. |
|
static |
Represents the uninitialized xtd::io::directory_info object. This field is constant.