Date: Mon, 10 Aug 1998 09:41:14 +0300 (IDT) From: Eli Zaretskii To: =?iso-8859-1?Q?Jorge_Iv=E1n_Meza_Mart=EDnez?= cc: djgpp AT delorie DOT com Subject: Re: readdir question In-Reply-To: <000401bdc3bd$8ec5b9c0$0b1f1bc4@enterprise-z> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Sun, 9 Aug 1998, =?iso-8859-1?Q?Jorge_Iv=E1n_Meza_Mart=EDnez?= wrote: > |#include > |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.