Home > Net >  How to retrieve full file path from DIR pointer?
How to retrieve full file path from DIR pointer?

Time:10-04

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.

CodePudding user response:

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.

  • Related