C++

List Files and Directories (multiplatform) in C++

CONTENT OF SNIPPET

Sample listing of files and directories. The method works on Linux like Windows (in any case Vista / Seven because not tested on XP and before, but Vista / Seven are compatible POSIX not XP and before, so not on that it works).




The operation is simple, we use functions of the POSIX standard, any compatible system can use it without any problem.

C++ SOURCE / EXAMPLE:

CONCLUSION:

The code is in C ++ (use of cost) but it is identical in C. opendir allows to open the directory, readdir to read it and close the farm. For the system, a directory is a folder just like a file, so to know if it is a folder and possibly listed so recursively, then we must call opendir on the directory which we just retrieved the name.

It is certainly possible to do otherwise but I have not looked for this side yet.

 

About the author

admin

Leave a Comment