Exposes static 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. More... | |
class | file_iterator |
Represent file iterator used by xtd::io::directory. More... | |
class | file_system_entry_iterator |
Represent file system iterator used by xtd::io::directory. More... | |
Public Static Methods | |
static xtd::io::directory_info | create_directory (const xtd::string &path) |
Creates all directories and subdirectories in the specified path unless they already exist. | |
static xtd::io::directory::directory_iterator | enumerate_directories (const xtd::string &path) |
Returns an enumerable collection of directory full names in a specified path. | |
static xtd::io::directory::directory_iterator | enumerate_directories (const xtd::string &path, const xtd::string &search_pattern) |
Returns an enumerable collection of directory full names that match a search pattern in a specified path. | |
static xtd::io::directory::file_iterator | enumerate_files (const xtd::string &path) |
Returns an enumerable collection of full file names in a specified path. | |
static xtd::io::directory::file_iterator | enumerate_files (const xtd::string &path, const xtd::string &search_pattern) |
Returns an enumerable collection of full file names that match a search pattern in a specified path. | |
static xtd::io::directory::file_system_entry_iterator | enumerate_file_system_entries (const xtd::string &path) |
Returns an enumerable collection of file names and directory names in a specified path. | |
static xtd::io::directory::file_system_entry_iterator | enumerate_file_system_entries (const xtd::string &path, const xtd::string &search_pattern) |
Returns an enumerable collection of file names and directory names that match a search pattern in a specified path. | |
static bool | exists (const xtd::string &path) |
Determines whether the given path refers to an existing directory on disk. | |
static xtd::date_time | get_creation_time (const xtd::string &path) |
Gets the creation date and time of a directory. | |
static xtd::string | get_current_directory () |
Gets the current working directory of the application. | |
static std::vector< xtd::string > | get_directories (const xtd::string &path) |
Returns the names of subdirectories (including their paths) in the specified directory. | |
static std::vector< xtd::string > | get_directories (const xtd::string &path, const xtd::string &search_pattern) |
Returns the names of subdirectories (including their paths) that match the specified search pattern in the specified directory. | |
static xtd::string | get_directory_root (const xtd::string &path) |
Returns the volume information, root information, or both for the specified path. | |
static std::vector< xtd::string > | get_files (const xtd::string &path) |
Returns the names of files (including their paths) in the specified directory. | |
static std::vector< xtd::string > | get_files (const xtd::string &path, const xtd::string &search_pattern) |
Returns the names of files (including their paths) that match the specified search pattern in the specified directory. | |
static std::vector< xtd::string > | get_file_system_entries (const xtd::string &path) |
Returns the names of all files and subdirectories in a specified path. | |
static std::vector< xtd::string > | get_file_system_entries (const xtd::string &path, const xtd::string &search_pattern) |
Returns an array of file names and directory names that match a search pattern in a specified path. | |
static xtd::date_time | get_last_access_time (const xtd::string &path) |
Returns the date and time the specified file or directory was last accessed. | |
static xtd::date_time | get_last_write_time (const xtd::string &path) |
Returns the date and time the specified file or directory was last written to. | |
static std::vector< xtd::string > | get_logical_drives () |
Retrieves the names of the logical drives on this computer in the form "<drive letter>:\". | |
static xtd::io::directory_info | get_parent (const xtd::string &path) |
Retrieves the parent directory of the specified path, including both absolute and relative paths. | |
static xtd::io::file_permissions | get_permissions (const xtd::string &path) |
Gets the xtd::io::file_permissions of the directory on the path. | |
static void | move (const xtd::string &source_dir_name, const xtd::string &dest_dir_name) |
Moves a file or a directory and its contents to a new location. | |
static void | remove (const xtd::string &path) |
Deletes an empty directory from a specified path. | |
static void | remove (const xtd::string &path, bool recursive) |
Deletes the specified directory and, if indicated, any subdirectories and files in the directory. | |
static void | set_creation_time (const xtd::string &path, const xtd::date_time &creation_time) |
Sets the creation date and time for the specified file or directory. | |
static void | set_creation_time (const xtd::string &path, time_t creation_time) |
Sets the creation date and time for the specified file or directory. | |
static void | set_current_directory (const xtd::string &path) |
Sets the application's current working directory to the specified directory. | |
static void | set_last_access_time (const xtd::string &path, const xtd::date_time &last_access_time) |
Sets the date and time the specified file or directory was last accessed. | |
static void | set_last_write_time (const xtd::string &path, const xtd::date_time &last_write_time) |
Sets the date and time a directory was last written to. | |
static void | set_permissions (const xtd::string &path, xtd::io::file_permissions permissions) |
Sets the specified xtd::io::file_permissions of the directory on the specified path. | |
|
static |
Creates all directories and subdirectories in the specified path unless they already exist.
path | The directory to create. |
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 creates and deletes the specified directory: @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 di("c:\MyDir"); try { // Determine whether the directory exists. if (di.exists()) { // Indicate that the directory already exists. console::write_line("That path exists already."); return; } // Try to create the directory. di.create(); console::write_line("The directory was created successfully."); // Delete the directory. di.remove(); console::write_line("The directory was deleted successfully."); } catch (const exception& e) { console::write_line("The process failed: {0}", e.to_string()); } } }; startup_(program::main); @endicode @par Examples To create the directory C:\Users\User1\Public\Html when the current directory is C:\Users\User1, use any of the following calls to ensure that the backslash is interpreted properly: @icode{cpp} directory::create_directory("Public\Html"); directory::create_directory("\Users\User1\Public\Html"); directory::create_directory("c:\Users\User1\Public\Html"); |
|
static |
Returns an enumerable collection of directory full names in a specified path.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
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 rExample The following example enumerates the top-level directories in a specified path. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::collections::generic; using namespace xtd::io; class program { public: static auto main() { try { // Set a variable to the My Documents path. string doc_path = environment::get_folder_path(environment::special_folder::my_documents); list<string> dirs(begin(directory::enumerate_directories(doc_path)), end(directory::enumerate_directories(doc_path))); for (auto dir : dirs) { console::write_line("{}", dir.substring(dir.last_index_of(path::directory_separator_char()) + 1)); } console::write_line("{} directories found.", dirs.size()); } catch (const unauthorized_access_exception& ex) { console::write_line(ex.message()); } catch (const path_too_long_exception& ex) { console::write_line(ex.message()); } } }; |
|
static |
Returns an enumerable collection of directory full names that match a search pattern in a specified path.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
search_pattern | The search string to match against the names of directories in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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 rExample The following example enumerates the top-level directories in a specified path that match a specified search pattern. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::collections::generic; using namespace xtd::io; class program { public: static auto main() { try { string dir_path = R"(\archives\2009\reports)"; // Create a List collection. auto dirs = list<string>(begin(directory::enumerate_directories(dir_path, "dv_*")), end(directory::enumerate_directories(dir_path, "dv_*"))); // Show results. for (auto dir : dirs) { // Remove path information from string. console::write_line("{0}", dir.substring(dir.last_index_of("\") + 1)); } console::write_line("{0} directories found.", dirs.size()); } catch (const unauthorized_access_exception& ex) { console::write_line(ex.message()); } catch (const path_too_long_exception& ex) { console::write_line(ex.message()); } } }; startup_(program::main); @endicode @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. <table class="markdownTable"> <tr class="markdownTableHead"> <th class="markdownTableHeadNone"> Wildcard specifier |
Matches
* (asterisk)
Zero or more characters in that position.
? (question mark)
Zero or one character in that position.
|
static |
Returns an enumerable collection of full file names in a specified path.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
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()); } } };
|
static |
Returns an enumerable collection of full file names that match a search pattern in a specified path.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
search_pattern | The search string to match against the names of files in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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, "*.txt"); 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); @endicode @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 searchPattern. <table class="markdownTable"> <tr class="markdownTableHead"> <th class="markdownTableHeadNone"> 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 search_pattern string "*t" searches for all names in path ending with the letter "t". The search_attern string "s*" searches for all names in path beginning with the letter "s".
|
static |
Returns an enumerable collection of file names and directory names in a specified path.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
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:\"). |
|
static |
Returns an enumerable collection of file names and directory names that match a search pattern in a specified path.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
serach_pattern | The search string to match against the names of file-system entries in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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:\"). @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 searchPattern. <table class="markdownTable"> <tr class="markdownTableHead"> <th class="markdownTableHeadNone"> 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 search_pattern string "*t" searches for all names in path ending with the letter "t". The search_attern string "s*" searches for all names in path beginning with the letter "s".
|
static |
Determines whether the given path refers to an existing directory on disk.
path | The path to test. |
|
static |
Gets the creation date and time of a directory.
path | The path of the directory. |
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 @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; The following example gets the creation time of the specified directory. class program { public: static auto main() { try { // Get the creation time of a well-known directory. date_time dt = directory::get_creation_time(environment::current_directory()); /// // Give feedback to the user. if (date_time::now().subtract(dt).total_days() > 364) { console::write_line("This directory is over a year old."); } else if (date_time::now().subtract(dt).total_days() > 30) { console::write_line("This directory is over a month old."); } else if (date_time::now().subtract(dt).total_days() <= 1) { console::write_line("This directory is less than a day old."); } else { console::write_line("This directory was created on {0}", dt); } } catch (const exception& e) { console::write_line("The process failed: {0}", e.to_string()); } } }; |
|
static |
Gets the current working directory of the application.
xtd::unauthorized_access_exception | The caller does not have the required permission. |
xtd::not_supported_exception | The operating system does not have current directory functionality. |
|
static |
Returns the names of subdirectories (including their paths) in the specified directory.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
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 takes an array of file or directory names on the command line, determines what kind of name it is, and processes it appropriately. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::collections::generic; using namespace xtd::io; class program { public: static auto main(const list<string>& args) { for (string path : args) { if (file::exists(path)) { // This path is a file process_file(path); } else if(directory::exists(path)) { // This path is a directory process_directory(path); } else { console::write_line("{0} is not a valid file or directory.", path); } } } // Process all files in the directory passed in, recurse on any directories // that are found, and process the files they contain. static void process_directory(const string& target_directory) { // Process the list of files found in the directory. std::vector<string> file_entries = directory::get_files(target_directory); for (string file_name : file_entries) process_file(file_name); // Recurse into subdirectories of this directory. std::vector<string> subdirectory_entries = directory::get_directories(target_directory); for (string subdirectory : subdirectory_entries) process_directory(subdirectory); } // Insert logic for processing found files here. static void process_file(const string& path) { console::write_line("Processed file '{0}'.", path); } }; startup_(program::main); @endicode @remarks This method is identical to xtd::io::directory::get_directories(string, string) with the asterisk (*) specified as the search pattern, so it returns all subdirectories. @remarks The xtd::io::directory::enumerate_directories and xtd::io::directory::get_directories methods differ as follows: When you use xtd::io::directory::enumerate_directories, you can start enumerating the collection of names before the whole collection is returned; when you use xtd::io::directory::get_directories, you must wait for the whole array of names to be returned before you can access the array. Therefore, when you are working with many files and directories, xtd::io::directory::enumerate_directories can be more efficient. @remarks The path parameter can specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks The names returned by this method are prefixed with the directory information provided in path. @remarks The path parameter is not case-sensitive. @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. |
|
static |
Returns the names of subdirectories (including their paths) that match the specified search pattern in the specified directory.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
search_pattern | The search string to match against the names of subdirectories in path. This parameter can contain a combination of valid literal and wildcard characters, but it doesn't support regular expressions. |
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 @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::collections::generic; using namespace xtd::io; class program { public: static auto main() { try { // Only get subdirectories that begin with the letter "p." list<string> dirs = directory::get_directories(R"(c:\)", "p*"); console::write_line("The number of directories starting with p is {0}.", dirs.size()); for (string dir : dirs) { console::write_line(dir); } } catch (const exception& e) { console::write_line("The process failed: {0}", e.to_string()); } } }; startup_(program::main); @endicode @remarks This method returns all subdirectories directly under the specified directory that match the specified search pattern. If the specified directory has no subdirectories, or no subdirectories match the search_pattern parameter, this method returns an empty array. Only the top directory is searched. @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. <table class="markdownTable"> <tr class="markdownTableHead"> <th class="markdownTableHeadNone"> Wildcard specifier |
Matches
* (asterisk)
Zero or more characters in that position.
? (question mark)
Zero or one character in that position.
|
static |
Returns the volume information, root information, or both for the specified path.
path | The path of a file or directory. |
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 illustrates how to set the current directory and display the directory root. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; class program { public: static auto main() { // Create string for a directory. This value should be an existing directory // or the sample will throw a DirectoryNotFoundException. string dir = R"(C:\test)"; try { //Set the current directory. directory::set_current_directory(dir); } catch (const directory_not_found_exception& e) { console::write_line("The specified directory does not exist. {0}", e); } // Print to console the results. console::write_line("Root directory: {0}", directory::get_directory_root(dir)); console::write_line("Current directory: {0}", directory::get_current_directory()); } }; startup_(program::main); @endicode @remarks This method obtains the fully qualified path name of path, as returned by xtd::io::path::get_full_path, and returns root directory information. The specified path is not required to exist. @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks The path parameter is not case-sensitive. @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. |
|
static |
Returns the names of files (including their paths) in the specified directory.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
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 demonstrates how to use the GetFiles method to return file names from a user-specified location. The example is configured to catch all errors common to this method. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::collections::generic; using namespace xtd::io; class program { public: static auto main(const std::vector<list>& args) { for (string path : args) { if (file::exists(path)) { // This path is a file process_file(path); } else if(directory::exists(path)) { // This path is a directory process_directory(path); } else { console::write_line("{0} is not a valid file or directory.", path); } } } // Process all files in the directory passed in, recurse on any directories // that are found, and process the files they contain. static void process_directory(const string& target_directory) { // Process the list of files found in the directory. std::vector<string> file_entries = directory::get_files(target_directory); for (string file_name : file_entries) process_file(file_name); // Recurse into subdirectories of this directory. std::vector<string> subdirectory_entries = directory::get_directories(target_directory); for (string subdirectory : subdirectory_entries) process_directory(subdirectory); } // Insert logic for processing found files here. static void process_file(const string& path) { console::write_line("Processed file '{0}'.", path); } }; startup_(program::main); @endicode @remarks The xtd::io::directory::enumerate_files and xtd::io::directory::get_files methods differ as follows: When you use xtd::io::directory::enumerate_files, you can start enumerating the collection of names before the whole collection is returned; when you use xtd::io::directory::get_files, you must wait for the whole array of names to be returned before you can access the array. Therefore, when you are working with many files and directories, xtd::io::directory::enumerate_files can be more efficient. @remarks The returned file names are appended to the supplied path parameter. @remarks This method is identical to xtd::io::directory::get_files(string, string) with the asterisk (*) specified as the search pattern. @remarks The path parameter can specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks The order of the returned file names is not guaranteed; use the std:::sort method if a specific sort order is required. @remarks The path parameter is not case-sensitive. @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. |
|
static |
Returns the names of files (including their paths) that match the specified search pattern in the specified directory.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
search_pattern | The search string to match against the names of files in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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 counts the number of files that begin with the specified letter. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::collections::generic; using namespace xtd::io; class program { public: static auto main() { try { // Only get files that begin with the letter "c". list<string> dirs = directory::get_files(R"(c:", "c*)"); console::write_line("The number of files starting with c is {0}.", dirs.size()); for (string dir : dirs) { console::write_line(dir); } } catch (const exception& e) { console::write_line("The process failed: {0}", e.to_string()); } } }; |
Wildcard specifier | Matches |
---|---|
* (asterisk) | Zero or more characters in that position. |
? (question mark) | Zero or one character in that position. |
|
static |
Returns the names of all files and subdirectories in a specified path.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
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 uses the xtd::io::directory::get_file_system_entries method to fill an array of strings with the names of all files and subdirectories in a user-specified location and prints each string in the array to the console. The example is configured to catch all errors common to this method. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::collections::generic; class program { public: static auto main() { program snippets; string path = io::directory::get_current_directory(); string filter = "*.exe"; snippets.print_file_system_entries(path); snippets.print_file_system_entries(path, filter); snippets.get_logical_drives(); snippets.get_parent(path); snippets.move("C:\proof", "C:\Temp"); } void print_file_system_entries(const string& path) { try { // Obtain the file system entries in the directory path. list<string> directory_entries = io::directory::get_file_system_entries(path); for (xtd::string str : directory_entries) { console::write_line(str); } } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } catch (const io::directory_not_found_exception&) { console::write_line("The path encapsulated in the directory object does not exist."); } } void print_file_system_entries(string path, string pattern) { try { // Obtain the file system entries in the directory path that match the pattern. list<string> directory_entries = io::directory::get_file_system_entries(path, pattern); for (string str : directory_entries) { console::write_line(str); } } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } catch (const io::directory_not_found_exception&) { console::write_line("The path encapsulated in the directory object does not exist."); } } // Print out all logical drives on the system. void get_logical_drives() { try { list<string> drives = io::directory::get_logical_drives(); for (string str : drives) { console::write_line(str); } } catch (const io::io_exception&) { console::write_line("An I/O error occurs."); } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } } void get_parent(const string& path) { try { io::directory_info directory_info = io::directory::get_parent(path); console::write_line(directory_info.full_name()); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } } void move(const string& source_path, const string& destination_path) { try { io::directory::move(source_path, destination_path); console::write_line("The directory move is complete."); } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } catch (const io::io_exception&) { console::write_line("An attempt was made to move a directory to a different volume, or dest_dir_name already exists."); } } }; startup_(program::main); @endicode @remarks The order of the returned file and directory names is not guaranteed; use the std::sort method if a specific sort order is required. @remarks The xtd::io::directory::enumerate_fileSystem_entries and xtd::io::directory::get_file_system_entries methods differ as follows: When you use xtd::io::directory::enumerate_file_system_entries, you can start enumerating the collection of entries before the whole collection is returned; when you use xtd::io::directory::get_file_system_entries, you must wait for the whole array of entries to be returned before you can access the array. Therefore, when you are working with many files and directories, xtd::io::directory::enumerate_file_system_enties can be more efficient. @remarks This method is identical to xtd::io::directory::get_file_system_entries with the asterisk (*) specified as the search pattern. @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks The path parameter is not case-sensitive. @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. |
|
static |
Returns an array of file names and directory names that match a search pattern in a specified path.
path | The relative or absolute path to the directory to search. This string is not case-sensitive. |
serach_pattern | The search string to match against the names of file and directories in path. This parameter can contain a combination of valid literal path and wildcard (* and ?) characters, but it doesn't support regular expressions. |
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 uses the xtd::io::directory::get_file_system_entries method to fill an array of strings with the names of all files matching a user-specified filter in a specific location and prints each string in the array to the console. The example is configured to catch all errors common to this method. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::collections::generic; class program { public: static auto main() { program snippets; string path = io::directory::get_current_directory(); string filter = "*.exe"; snippets.print_file_system_entries(path); snippets.print_file_system_entries(path, filter); snippets.get_logical_drives(); snippets.get_parent(path); snippets.move("C:\proof", "C:\Temp"); } void print_file_system_entries(const string& path) { try { // Obtain the file system entries in the directory path. list<string> directory_entries = io::directory::get_file_system_entries(path); for (xtd::string str : directory_entries) { console::write_line(str); } } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } catch (const io::directory_not_found_exception&) { console::write_line("The path encapsulated in the directory object does not exist."); } } void print_file_system_entries(string path, string pattern) { try { // Obtain the file system entries in the directory path that match the pattern. list<string> directory_entries = io::directory::get_file_system_entries(path, pattern); for (string str : directory_entries) { console::write_line(str); } } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } catch (const io::directory_not_found_exception&) { console::write_line("The path encapsulated in the directory object does not exist."); } } // Print out all logical drives on the system. void get_logical_drives() { try { list<string> drives = io::directory::get_logical_drives(); for (string str : drives) { console::write_line(str); } } catch (const io::io_exception&) { console::write_line("An I/O error occurs."); } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } } void get_parent(const string& path) { try { io::directory_info directory_info = io::directory::get_parent(path); console::write_line(directory_info.full_name()); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } } void move(const string& source_path, const string& destination_path) { try { io::directory::move(source_path, destination_path); console::write_line("The directory move is complete."); } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } catch (const io::io_exception&) { console::write_line("An attempt was made to move a directory to a different volume, or dest_dir_name already exists."); } } }; startup_(program::main); @endicode @remarks The returned file names are appended to the supplied path parameter and the order of the returned file names is not guaranteed; use the std::sort method if a specific sort order is required. @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. <table class="markdownTable"> <tr class="markdownTableHead"> <th class="markdownTableHeadNone"> Wildcard specifier |
Matches
* (asterisk)
Zero or more characters in that position.
? (question mark)
Zero or one character in that position.
|
static |
Returns the date and time the specified file or directory was last accessed.
path | The file or directory for which to obtain access date and time information. |
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 demonstrates how to use GetLastAccessTime. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; class program { public: static auto main() { try { string path = R"(c:\MyDir)"; if (!directory::exists(path)) { directory::create_directory(path); } directory::set_last_access_time(path, {1985, 5, 4}); // Get the creation time of a well-known directory. date_time dt = directory::get_last_access_time(path); console::write_line("The last access time for this directory was {0}", dt); // Update the last access time. directory::set_last_access_time(path, date_time::now()); dt = directory::get_last_access_time(path); console::write_line("The last access time for this directory was {0}", dt); } catch (const exception& e) { console::write_line("The process failed: {0}", e.to_string()); } } }; startup_(program::main); @endicode @note This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system. @remarks This method is identical to xtd::io::file::get_last_access_time. @remarks If the directory described in the path parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time. @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks The path parameter is not case-sensitive. @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. |
|
static |
Returns the date and time the specified file or directory was last written to.
path | The file or directory for which to obtain modification date and time information. |
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 demonstrates how to use xtd::io::directory::get_last_write_time. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; class program { public: static auto main() { try { string path = R"(c:\MyDir)"; if (!directory::exists(path)) { directory::create_directory(path); } directory::set_last_write_time(path, {1985, 5, 4}); // Get the creation time of a well-known directory. date_time dt = directory::get_last_write_time(path); console::write_line("The last write time for this directory was {0}", dt); // Update the last write time. directory::set_last_write_time(path, date_time::now()); dt = directory::get_last_write_time(path); console::write_line("The last write time for this directory was {0}", dt); } catch (const exception& e) { console::write_line("The process failed: {0}", e.to_string()); } } }; startup_(program::main); @endicode @note This method may return an inaccurate value, because it uses native functions whose values may not be continuously updated by the operating system. @remarks If the directory described in the path parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time. @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks The path parameter is not case-sensitive. @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. |
|
static |
Retrieves the names of the logical drives on this computer in the form "<drive letter>:\".
xtd::io::io_exception | An I/O error occurred (for example, a disk error). |
xtd::unauthorized_access_exception | The caller does not have the required permission. |
|
static |
Retrieves the parent directory of the specified path, including both absolute and relative paths.
path | The path for which to retrieve the parent directory. |
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 demonstrates how to use the xtd::io::directory::get_parent method to retrieve the parent directory of a user-specified location, "path". The value returned by the xtd::io::directory::get_parent method is then printed to the console. The example is configured to catch all errors common to this method. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::collections::generic; class program { public: static auto main() { program snippets; string path = io::directory::get_current_directory(); string filter = "*.exe"; snippets.print_file_system_entries(path); snippets.print_file_system_entries(path, filter); snippets.get_logical_drives(); snippets.get_parent(path); snippets.move("C:\proof", "C:\Temp"); } void print_file_system_entries(const string& path) { try { // Obtain the file system entries in the directory path. list<string> directory_entries = io::directory::get_file_system_entries(path); for (xtd::string str : directory_entries) { console::write_line(str); } } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } catch (const io::directory_not_found_exception&) { console::write_line("The path encapsulated in the directory object does not exist."); } } void print_file_system_entries(string path, string pattern) { try { // Obtain the file system entries in the directory path that match the pattern. list<string> directory_entries = io::directory::get_file_system_entries(path, pattern); for (string str : directory_entries) { console::write_line(str); } } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } catch (const io::directory_not_found_exception&) { console::write_line("The path encapsulated in the directory object does not exist."); } } // Print out all logical drives on the system. void get_logical_drives() { try { list<string> drives = io::directory::get_logical_drives(); for (string str : drives) { console::write_line(str); } } catch (const io::io_exception&) { console::write_line("An I/O error occurs."); } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } } void get_parent(const string& path) { try { io::directory_info directory_info = io::directory::get_parent(path); console::write_line(directory_info.full_name()); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } } void move(const string& source_path, const string& destination_path) { try { io::directory::move(source_path, destination_path); console::write_line("The directory move is complete."); } catch (const security::security_exception&) { console::write_line("The caller does not have the required permission."); } catch (const argument_exception&) { console::write_line("path is an empty string, contains only white spaces, or contains invalid characters."); } catch (const io::io_exception&) { console::write_line("An attempt was made to move a directory to a different volume, or dest_dir_name already exists."); } } }; startup_(program::main); @endicode @remarks The path parameter can specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @remarks Trailing spaces are removed from the end of the path parameter before getting the directory. @remarks The string returned by this method consists of all characters in the path up to, but not including, the last xtd::io::path::directory_separator_char or alt_directory_separator_char. For example, passing the path "C:\Directory\SubDirectory\test.txt" to xtd::io::directory::get_parent returns "C:\Directory\SubDirectory". Passing "C:\Directory\SubDirectory" returns "C:\Directory". However, passing "C:\Directory\SubDirectory" returns "C:\Directory\SubDirectory", because the ending directory separator is after "SubDirectory". |
|
static |
Gets the xtd::io::file_permissions of the directory on the path.
path | The path to the directory. |
xtd::io::directory_not_found_exception | if directory src does not exists. |
|
static |
Moves a file or a directory and its contents to a new location.
source_dir_name | The path of the file or directory to move. |
dest_dir_name | The path to the new location for source_dir_name. If source_dir_name is a file, then dest_dir_name must also be a file name. |
xtd::io::io_exception | An attempt was made to move a directory to a different volume. -or- dest_dir_name already exists. See the Note in the Remarks section. -or- The source_dir_name and dest_dir_name parameters refer to the same file or directory. -or- The directory or a file within it is being used by another process. |
xtd::argument_exception | source_dir_name or dest_dir_name is a zero-length string, contains only white space, or contains one or more invalid characters. You can query for invalid characters with the xtd::path::io::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 path specified by sourceDirName is invalid (for example, it is on an unmapped drive). |
|
static |
Deletes an empty directory from a specified path.
path | The name of the empty directory to remove. This directory must be writable and empty. |
xtd::io::io_exception | A file with the same name and location specified by path exists. -or- The directory is the application's current working directory. -or- The directory specified by path is not empty. -or- The directory is read-only or contains a read-only file. -or- The directory is being used by another process. |
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 Exaample The following example shows how to create a new directory and subdirectory, and then delete only the subdirectory. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; class program { public: static auto main() { string sub_path = R"(C:\NewDirectory\NewSubDirectory)"; try { directory::create_directory(sub_path); directory::remove(sub_path); bool directory_exists = directory::exists(R"(C:\NewDirectory)"); bool sub_directory_exists = directory::exists(sub_path); console::write_line("top-level directory exists: {0}", directory_exists); console::write_line("sub-directory exists: {0}", sub_directory_exists); } catch (const exception& e) { console::write_line("The process failed: {0}", e.message()); } } }; |
|
static |
Deletes the specified directory and, if indicated, any subdirectories and files in the directory.
path | The name of the directory to remove. |
recursive | true to remove directories, subdirectories, and files in path; otherwise, false. |
xtd::io::io_exception | A file with the same name and location specified by path exists. -or- The directory is the application's current working directory. -or- The directory specified by path is not empty. -or- The directory is read-only or contains a read-only file. -or- The directory is being used by another process. |
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 create a new directory, subdirectory, and file in the subdirectory, and then recursively delete all the new items. @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; class program { public: static auto main() { string top_path = R"(C:\NewDirectory)"; string sub_path = R"(C:\NewDirectory\NewSubDirectory)"; try { directory::create_directory(sub_path); block_scope_(stream_writer writer(sub_path + R"(\example.txt)")) { writer.write_line("content added"); } directory::remove(top_path, true); bool directory_exists = directory::exists(top_path); console::write_line("top-level directory exists: {0}", directory_exists); } catch (const exception& e) { console::write_line("The process failed: {0}", e.message()); } } }; |
|
static |
Sets the creation date and time for the specified file or directory.
path | The file or directory for which to set the creation date and time information. |
creation_time | The date and time the file or directory was last written to. This value is expressed in local time. |
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 @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; class program { public: static auto main() { // Set the directory. string n = R"(C:\test\newdir)"; //Create the directory. try { directory::create_directory(n); } catch (const io_exception& e) { console::write_line(e); } //Set the creation and last access times to a variable DateTime value. directory::set_creation_time(n, {2002, 1, 3}); directory::set_last_access_time(n, {2002, 1, 3}); // Print to console the results. console::write_line("Creation Date: {0}", directory::get_creation_time(n)); console::write_line("Last write time: {0}", directory::get_last_write_time(n)); console::write_line("Last access time: {0}", directory::get_last_access_time(n)); //Set the last write time to a different value. directory::set_last_write_time(n, {1999, 1, 1}); console::write_line("Changed last write time: {0}", directory::get_last_write_time(n)); } }; |
// Obviously, since this sample deals with dates and times, the output will vary // depending on when you run the executable. Here is one example of the output: //Creation Date: 1/3/2002 12:00:00 AM //Last write time: 12/31/1998 4:00:00 PM //Last access time: 1/2/2002 4:00:00 PM //Changed last write time: 1/1/1999 12:00:00 AM
|
static |
Sets the creation date and time for the specified file or directory.
path | The file or directory for which to set the creation date and time information. |
creation_time | The date and time the file or directory was last written to. This value is expressed in local time. |
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 @icode{cpp} #include <xtd/xtd> using namespace xtd; using namespace xtd::io; class program { public: static auto main() { // Set the directory. string n = R"(C:\test\newdir)"; //Create the directory. try { directory::create_directory(n); } catch (const io_exception& e) { console::write_line(e); } //Set the creation and last access times to a variable DateTime value. directory::set_creation_time(n, {2002, 1, 3}); directory::set_last_access_time(n, {2002, 1, 3}); // Print to console the results. console::write_line("Creation Date: {0}", directory::get_creation_time(n)); console::write_line("Last write time: {0}", directory::get_last_write_time(n)); console::write_line("Last access time: {0}", directory::get_last_access_time(n)); //Set the last write time to a different value. directory::set_last_write_time(n, {1999, 1, 1}); console::write_line("Changed last write time: {0}", directory::get_last_write_time(n)); } }; |
// Obviously, since this sample deals with dates and times, the output will vary // depending on when you run the executable. Here is one example of the output: //Creation Date: 1/3/2002 12:00:00 AM //Last write time: 12/31/1998 4:00:00 PM //Last access time: 1/2/2002 4:00:00 PM //Changed last write time: 1/1/1999 12:00:00 AM
|
static |
Sets the application's current working directory to the specified directory.
path | The path to which the current working directory is set. |
xtd::argument_exception | Attempted to set to an empty string (""). |
xtd::io::io_exception | An I/O error occurred. |
xtd::io::directory_not_found_exception | Attempted to set a local path that cannot be found. |
xtd::security::security_exception | The caller does not have the appropriate permission. |
|
static |
Sets the date and time the specified file or directory was last accessed.
path | The file or directory for which to set the access date and time information. |
last_access_time | An object that contains the value to set for the access date and time of path. This value is expressed in local time. |
xtd::argument_exception | Attempted to set to an empty string (""). |
xtd::io::io_exception | An I/O error occurred. |
xtd::io::directory_not_found_exception | Attempted to set a local path that cannot be found. |
xtd::security::security_exception | The caller does not have the appropriate permission. |
|
static |
Sets the date and time a directory was last written to.
path | The path of the directory. |
last_write_time | The date and time the directory was last written to. This value is expressed in local time. |
xtd::argument_exception | Attempted to set to an empty string (""). |
xtd::io::io_exception | An I/O error occurred. |
xtd::io::directory_not_found_exception | Attempted to set a local path that cannot be found. |
xtd::security::security_exception | The caller does not have the appropriate permission. |
|
static |
Sets the specified xtd::io::file_permissions of the directory on the specified path.
path | The path to the directory. |
attributes | A bitwise combination of the enumeration values. |
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, directory 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:\"). @remarks The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory. To obtain the current working directory, see xtd::io::directory::get_current_directory. @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. |