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

◆ create()

void xtd::io::directory_info::create ( )

Creates a directory.

Exceptions
xtd::io::io_exceptionThe directory cannot be created.
Examples
The following example checks whether a specified directory exists, creates the directory if it does not exist, and deletes the directory.
#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);
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::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
If the directory already exists, this method does nothing.
If the directory did not exist before calling this method, then any cached attribute information about the directory will be flushed if the creation is successful.
For a list of common I/O tasks, see Common I/O Tasks.