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

◆ parent()

xtd::io::directory_info xtd::io::directory_info::parent ( ) const

Gets the parent directory of a specified subdirectory.

Returns
The parent directory, or null if the path is null or if the file path denotes a root (such as \, C:\, or \server\share).
Exceptions
xtd::security::security_exceptionThe caller does not have the required permission.
Examples
The following example refers to the parent directory of a specified directory.
#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");
// Get a reference to the parent directory of the subdirectory you just made.
directory_info parent_dir = dis.parent();
console::write_line("The parent directory of '{0}' is '{1}'", dis.name(), parent_dir.name());
// Delete the parent directory.
di.remove(true);
}
};
startup_(program::main);
xtd::io::directory_info parent() const
Gets the parent directory of a specified subdirectory.
xtd::string name() const override
Gets the name of this xtd::io::directory_info instance.
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
To ensure consistent behavior across versions and to make your intent explicit, retrieve the value of one of the following properties on the xtd::io::directory_info instance returned by xtd::io::directory_info::parent.
For a list of common I/O tasks, see Common I/O Tasks.