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

◆ get_current_directory()

static xtd::string xtd::io::directory::get_current_directory ( )
static

Gets the current working directory of the application.

Returns
A string that contains the absolute path of the current working directory, and does not end with a backslash ().
Exceptions
xtd::unauthorized_access_exceptionThe caller does not have the required permission.
xtd::not_supported_exceptionThe operating system does not have current directory functionality.
Examples
The following example demonstrates how to use the xtd::io::directory::get_current_directory method.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::io;
class program {
public:
static auto main() {
try {
// Get the current directory.
string path = directory::get_current_directory();
string target = R"(c:\temp)";
console::write_line("The current directory is {0}", path);
if (!directory::exists(target)) {
directory::create_directory(target);
}
// Change the current directory.
environment::current_directory(target);
if (path.equals(directory::get_current_directory())) {
console::write_line("You are in the temp directory.");
} else {
console::write_line("You are not in the temp directory.");
}
} 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
Performs operations on std::basic_string instances that contain file or directory path information....
Definition path.h:36
#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
The current directory is distinct from the original directory, which is the one from which the process was started.
For a list of common I/O tasks, see Common I/O Tasks.