einpoklum
einpoklum

Reputation: 131656

Non-empty relative current path, in standard C++?

With C++17 (or Boost::filesystem), we can get the current path / current working directory using filesystem::current_path(). However - that gives us an absolute path.

We could also use an empty path as the relative current path - sometimes.

But - is it possible to obtain, portably, the equivalent of "." or "./" ? i.e. a non-empty relative current path?

Upvotes: 2

Views: 121

Answers (1)

einpoklum
einpoklum

Reputation: 131656

Use "." for the current directory.

std::filesystem will recognize "." as representing the current directory / path - regardless of the platform you're on. So, it will not just happen to work on Linux/Windows, it is guaranteed to work.

auto relative_current path = std::filesystem::path{"."};

Relevant wording in the standard: fs.path.generic.3.

This answer is basically due to @NathanOliver...

Upvotes: 2

Related Questions