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

◆ enumerate_directories() [1/2]

xtd::io::directory_info::directory_iterator xtd::io::directory_info::enumerate_directories ( ) const

Returns an enumerable collection of directory information in the current directory.

Returns
An xtd::io::directory_info::directory_iterator of directories in the current directory.
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
The following example enumerates the subdirectories under the "My Documents" directory.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
// Set a variable to the Documents path.
string doc_path = environment::get_folder_path(environment::special_folder::my_documents);
directory_info dirs(doc_path);
for (auto di : dirs.enumerate_directories()) {
console::write_line("{}", di.name());
}
}
};
startup_(program::main);
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
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
The xtd::io::directory_info::enumerate_directories and xtd::io::directory_info::get_directories methods differ as follows:
* When you use xtd::io::directory_info::enumerate_directories, you can start enumerating the collection of xtd::io::directory_info objects before the whole collection is returned.
* When you use xtd::io::directory_info::get_directories, you must wait for the whole array of xtd::io::directory_info objects to be returned before you can access the array.
Therefore, when you are working with many files and directories, xtd::io::directory_info::enumerate_directories can be more efficient.
This method pre-populates the values of the following xtd::io::directory_info properties: