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

◆ remove() [1/2]

void xtd::io::directory_info::remove ( ) const
overridevirtual

Deletes this xtd::io::directory_info if it is empty.

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 throws an exception if you attempt to delete a directory that is not empty.
#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 di1(R"(c:\MyDir)");
try {
// Create the directories.
di1.create();
di1.create_subdirectory("temp");
//This operation will not be allowed because there are subdirectories.
console::write_line("I am about to attempt to delete {0}", di1.name());
di1.remove();
console::write_line("The Delete operation was successful, which was unexpected.");
} catch (const exception&) {
console::write_line("The Delete operation failed as expected.");
}
}
};
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
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
For a list of common I/O tasks, see Common I/O Tasks.

Implements xtd::io::file_system_info.

Examples
file_info_move_to.cpp.