Returns an enumerable collection of full file names in a specified path.
- Parameters
-
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
- Returns
- An xtd::io::directory::directory_iterator of the full names (including paths) for the files in the directory specified by path.
- Exceptions
-
xtd::io::io_exception | The directory specified by path is a file. |
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::directory_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:\").
@par Examples
The following example shows how to retrieve all the text files from a directory and move them to a new directory. After the files are moved, they no longer exist in the original directory.
@icode{cpp}
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
string source_directory = R"(C:\current)";
string archive_directory = R"(C:\archive)"; |
try { auto txt_files = directory::enumerate_files(source_directory);
for (string current_file : txt_files) { string file_name = current_file.substring(source_directory.size() + 1); directory::move(current_file, path::combine(archive_directory, file_name)); } } catch (exception& e) { console::write_line(e.message()); } } };
startup_(program::main);