Re: Directory grep?

From: Todd A Laycock (tlayco1@uic.edu)
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 :-)
>
> -FIRE

This is found in section 3.13 of the FAQ at
http://www.circlemud.org/pub/CircleMUD/FAQ

----------
  struct dirent * ffile;
  DIR * my_dir;

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

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

  closedir(my_dir);

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: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



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