Mail Archives: cygwin/1998/10/02/15:14:42
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
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -