Are directory_iterator and/or recursive_directory_iterator guaranteed to return relative paths?

Viewed 339

Are std::filesystem::directory_iterator and/or std::filesystem::recursive_directory_iterator guaranteed to return std::filesystem::directory_entry objects with paths relative to the base directory they were initialized with?
Or may they return entries with absolute paths?

1 Answers

From Filesystem draft N4100:

The result of calling the path() member of the directory_entry object obtained by dereferencing a directory_iterator is a reference to a path object composed of the directory ar gument from which the iterator was constructed with filename of the directory entry appended as if by operator/=

So it seems that the answer is: the path is relative to the one that the iterator has been constructed with.

Related