Subject: RE: Troubles with opendir/readdir
From: [email-masked] (Kubat, Karel)

2 Oct 1998 15:14:42 -0700
Message-ID: <DDA85E014826D2118BE30000F6B276B315DA0B.cygnus.gnu-win32@WINNT_MAILEXCH>
To: [email-masked]

Craig:

> I posted to the list about a week or so ago about troubles 
> that I'm having with
> opendir/readdir/closedir functions.  Although I know how they 
> are supposed to
> work, when I open a directory which has a number of files in 
> it, it is as
> though they are not seen by the functions.  I never get any 
> errors, but I also
> never get any files.  Can anyone offer any thoughts on what I 
> might be doing
> wrong with these functions?  I know that they must work or 
> many other programs
> would fail.

The following works fine for me. Add your own headers and ignore the Strtab
struct, it's a local thing of the proggy. Same goes for the functions
warning() and addstrtab().

Cheers, Karel

/* read all entries from current dir */

#include "cptree.h"

void readentries (Strtab *tab, char *dirname)
{
    DIR *d;
    struct dirent *dent;
    
    if (! (d = opendir (".")) )
    {
	warning ("cannot read directory entries in %s", dirname);
	return;
    }
    
    while ( (dent = readdir (d)) )
    {
	/* avoid . and .. */
	if (! strcmp (dent->d_name, ".") ||
	    ! strcmp (dent->d_name, ".."))
	    continue;
	addstrtab (tab, dent->d_name);
    }
}
    
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".