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

◆ create_subdirectory()

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.

Parameters
pathThe specified path. This cannot be a different disk volume or Universal Naming Convention (UNC) name.
Returns
The last directory specified in path.
Exceptions
xtd::argument_exceptionpath does not specify a valid file path or contains invalid xtd::io::directory_info characters.
xtd::io::directory_not_found_exceptionThe specified path is invalid, such as being on an unmapped drive.
xtd::io::io_exceptionThe subdirectory cannot be created.
-or-
A file or directory already has the name specified by path.
xtd::io::path_too_long_exceptionThe specified path, file name, or both exceed the system-defined maximum length.
xtd::security::security_exceptionThe caller does not have code access permission to create the directory.
xtd::not_supported_exceptionpath 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.