delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/10/02:41:38

Date: Mon, 10 Aug 1998 09:41:14 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: =?iso-8859-1?Q?Jorge_Iv=E1n_Meza_Mart=EDnez?= <jimeza AT usa DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: readdir question
In-Reply-To: <000401bdc3bd$8ec5b9c0$0b1f1bc4@enterprise-z>
Message-ID: <Pine.SUN.3.91.980810094055.1429C-100000@is>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019