How to retrieve full file path from DIR pointer?

338 Views Asked by At

From a DIR* variable from <dirent.h>, how do I get the full file path (e.g. "/home/ubuntu/Desktop/planning")?

Note: This needs to work on Linux.

1

There are 1 best solutions below

0
Sam Varshavchik On BEST ANSWER

There's nothing in the DIR object that gives you the name of the directory that the DIR object is reading. There is no function in the C library that does this.

You will need to implement this logic yourself. Wherever you open a DIR: save the name of the directory you opened, and consult it as needed.

Or, in modern C++, you can also use the filesystem library, instead of this C API.