How can I list the whole file in a directory in POSIX / c C ++?

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?

+3
source share
4 answers

POSIX.1-2001 specifies opendir, readdirand closedir, seekdir, rewinddirand telldir. Your platform probably contains man pages describing how to use them.

, MS, , -, FindFirst FindNext , , , , ; , Win32.

+4

GCC, . : GNU

+3

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;
    }
}
+3

getdents() readdir() Linux

+1
source

All Articles