Re: Directory grep?

From: Todd A Laycock (
Date: 04/18/02

On Wed, 17 Apr 2002, Shane P. Lee wrote:

> I am trying to scan a directory and pipe it's contents back to
> the MUD. I've tried a million different ways, but can't seem to
> get anything to work. I've been working on this for several days,
> which is unbelieveable for me. Normally I get it to work, or find
> some way around it.
> I'm needing to scan a series of directories from "a" to "z" and
> only return the filenames inside. I was thinking maybe the mailall
> snippet would help, but I can't find anything useful inside it, and
> as most of you know, I'm no newbie.
> If anyone can help, please send me something, if only an idea.
> BTW, I'm on a Linux Redhat server. Glad I remembered that :-)

This is found in section 3.13 of the FAQ at

  struct dirent * ffile;
  DIR * my_dir;

  if (!(my_dir = opendir("foo")))

  while (1) {
    if (!(dirent = readdir(my_dir)))
    printf("%s\n", dirent->d_name);


The dirent structure contains only two useful elements, the file's name
(d_name) and the files length (d_reclen).

Thanks to Daniel Koepke for the above.

Todd Laycock

   | FAQ: |
   | Archives: |
   | Newbie List:   |

This archive was generated by hypermail 2b30 : 06/25/03 PDT