Mail Archives: djgpp/1998/08/10/02:41:38
On Sun, 9 Aug 1998, =?iso-8859-1?Q?Jorge_Iv=E1n_Meza_Mart=EDnez?= wrote:
> |#include <dirent.h>
> |struct dirent *readdir(DIR *dir);
> |
> |DIR *d = opendir( argv[1] );
> |
> |while ((de = readdir(d)))
> | cout >> de->d_name;
> |
> |closedir ( d );
>
> but it does not read from other subdirectories, just the directory that I
> tell him and not its subdirectories.
`readdir' does NOT recursively traverse subdirectories. If you need
that, you will have to recurse on each subdirectory you find.
A somewhat easier way is to use the library function `ftw' which walks
the entire directory subtree calling a user-defined function on each
file. But `ftw' is less portable to other platforms, in case
portability is a concern in your case.
> from the "LibC Reference" I understood that setting "__opendir_flags"
> variable to "__OPENDIR_FIND_HIDDEN", the "opendir ( ... )" would seek for
> files thru subdirectories
Where did you see anything that implies such a thing? The docs says
this:
`__OPENDIR_FIND_HIDDEN'
Include hidden files and directories in the search. By default,
these are skipped.
The ``directories'' here goes with ``hidden'': it means to say that
this flag will cause `readdir' to find hidden directories and hidden
files as well as normal files/directories. It doesn't imply in any
way that `readdir' will recurse into subdirectories.
- Raw text -