delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/10/02/15:14:42

From: K DOT Kubat AT roccadefinance DOT nl (Kubat, Karel)
Subject: RE: Troubles with opendir/readdir
2 Oct 1998 15:14:42 -0700 :
Message-ID: <DDA85E014826D2118BE30000F6B276B315DA0B.cygnus.gnu-win32@WINNT_MAILEXCH>
To: gnu-win32 AT cygnus DOT com

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 -


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