Thread: Directory Nodes

  1. #1
    zsaniK Kinasz's Avatar
    Join Date
    Jan 2003
    Posts
    222

    Question Directory Nodes

    Does anybody know how to read contents of a directory into a c program?

    eg: fopen( directory_name, "r"); ???
    "Assumptions are the mother of all **** ups!"

  2. #2
    Registered User
    Join Date
    Aug 2002
    Posts
    351
    Have a look at stat(2) and readdir(3).

  3. #3
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    getdents(2)

  4. #4
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187
    Code:
    #include <dirent.h>
    DIR *dp;
    struct dirent *dirp;
    dp=opendir("dirname");
    while((dirp=readdir(dp))!=NULL)
      printf("%s\n",dirp->d_name);
    Bugs not fixed
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

  5. #5
    template<typename T> threahdead's Avatar
    Join Date
    Sep 2002
    Posts
    214
    what bug?

  6. #6
    still a n00b Jaguar's Avatar
    Join Date
    Jun 2002
    Posts
    187
    >>what bug?

    The program gave only concept.
    It doesn't check the existence of ``dirname'' i.e.
    Code:
    if ((dp=opendir("dirname"))==NULL) {
      /* do some stuff */
      exit(1);
    }
    slackware 10.0; kernel 2.6.7
    gcc 3.4.0; glibc 2.3.2; vim editor
    migrating to freebsd 5.4

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  2. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  3. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  4. Replies: 6
    Last Post: 07-30-2003, 03:08 AM
  5. Directory reading trouble
    By samGwilliam in forum Linux Programming
    Replies: 0
    Last Post: 03-10-2002, 09:43 AM