1

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.

Adam Lee
  • 436
  • 1
  • 14
  • 49

1 Answers1

0

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.

Sam Varshavchik
  • 114,536
  • 5
  • 94
  • 148