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

◆ remove() [2/2]

void xtd::io::directory_info::remove ( bool  recursive) const

Deletes this instance of a DirectoryInfo, specifying whether to delete subdirectories and files.

Parameters
recursivetrue to delete this directory, its subdirectories, and all files; otherwise, false.
Exceptions
xtd::unauthorized_access_exceptionThe directory contains a read-only file.
xtd::io::directory_not_found_exceptionThe directory described by this xtd::io::directory_info object does not exist or could not be found.
xtd::io::io_exceptionThe directory is not empty.
-or-
The directory is the application's current working directory.
-or-
There is an open handle on the directory.
xtd::security::security_exceptionThe caller does not have the required permission.
Examples
The following example demonstrates deleting a directory. Because the directory is removed, first comment out the Delete line to test that the directory exists. Then uncomment the same line of code to test that the directory was removed successfully.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
// Make 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. The true indicates that if subdirectories
// or files are in this directory, they are to be deleted as well.
dis.remove(true);
// Delete the directory.
di.remove(true);
}
};
startup_(program::main);
void remove() const override
Deletes this xtd::io::directory_info if it is empty.
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...
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
If the xtd::io::directory_info has no files or subdirectories, this method deletes the xtd::io::directory_info even if recursive is false. Attempting to delete a xtd::io::directory_info that is not empty when recursive is false throws an xtd::io::io_exception.
For a list of common I/O tasks, see Common I/O Tasks.