I need to list the entire file in a directory, and then go to the subdirectory and do the same.
Ideally, the algorithm should work in the same way on linux macos [windows (outdated) no more].
UPDATE: I now know VFS, but I'm puzzled by using VFS to list dir. Any suggestion? Should I open the directory as a file?
POSIX.1-2001 specifies opendir, readdirand closedir, seekdir, rewinddirand telldir. Your platform probably contains man pages describing how to use them.
opendir
readdir
closedir
seekdir
rewinddir
telldir
, MS, , -, FindFirst FindNext , , , , ; , Win32.
FindFirst
FindNext
GCC, . : GNU
Boost Filesystem, Linux, Windows MacOS. recursive_directory_iterator , , .
#include "boost/filesystem.hpp" #include <iostream> int main() { namespace fs = boost::filesystem; fs::recursive_directory_iterator end; for ( fs::recursive_directory_iterator dir("./"); dir != end; ++dir ) { std::cout << *dir << std::endl; } }
getdents() readdir() Linux