xtd 0.2.0
Loading...
Searching...
No Matches

◆ get_directories() [2/2]

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.

Parameters
search_patternThe 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.
Returns
An array of type xtd::io::directory_info matching search_pattern.
Exceptions
xtd::io::directory_not_found_exceptionThe specified path is invalid, such as being on an unmapped drive.
xtd::security::security_exceptionThe caller does not have code access permission to create the directory.
Examples
TThe following example counts the directories in a path that contain the specified letter.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::collections::generic;
using namespace xtd::io;
class program {
public:
static auto main() {
try {
directory_info di(R"(c:\)");
// Get only subdirectories that contain the letter "p."
list<directory_info> dirs = di.get_directories("*p*");
console::write_line("The number of directories containing the letter p is {0}.", dirs.size());
for (directory_info di_next : dirs) {
console::write_line("The number of files in {0} is {1}", di_next, di_next.get_files().size());
}
} catch (const exception& e) {
console::write_line("The process failed: {0}", e.to_string());
}
}
};
startup_(program::main);
virtual size_type size() const noexcept
Returns the number of elements in the container, i.e. std::distance(xtd::collections::generic::list::...
Definition list.h:365
Represents a strongly typed list of objects that can be accessed by index. Provides methods to search...
Definition list.h:72
Defines the base class for predefined exceptions in the xtd namespace.
Definition exception.h:26
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories...
Definition directory_info.h:129
#define startup_(main_method)
Defines the entry point to be called when the application loads. Generally this is set either to the ...
Definition startup.h:175
@ e
The E key.
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.h:15
The xtd::io namespace contains types that allow reading and writing to files and data streams,...
Definition binary_reader.h:16
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.h:10
Remarks
search_pattern can be a combination of literal and wildcard characters, but it doesn't support regular expressions. The following wildcard specifiers are permitted in search_pattern.
Wildcard specifier Matches
* (asterisk) Zero or more characters in that position.
 ? (question mark) Zero or one character in that position.
Characters other than the wildcard are literal characters. For example, the string "*t" searches for all names in ending with the letter "t". ". The search_pattern string "s*" searches for all names in path beginning with the letter "s".
This method pre-populates the values of the following xtd::io::directory_info properties: