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.
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.
Copyright © 2021 Jogjafile Inc.
There's nothing in the
DIRobject that gives you the name of the directory that theDIRobject 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.