#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    4
    Rep Power
    0

    Writing "find" code


    I've got a project that writing "find" code in solaris.

    That is finding a file in current and sub directories.

    While I am looking for some example on the book for two days, but I have no idea where to start.

    I think I need to use recursion, but is it true?

    I am still a Unix beginner and the teacher and book didn't give me enough info...

    Please tell me the way of structure and concept.

    Thanks in advance.

    SQ
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    68
    Rep Power
    12
    Code:
    $ man opendir
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    4
    Rep Power
    0
    Originally posted by Kung Foo Master
    Code:
    $ man opendir
    Well, actually I meant writing a "find" code in C code...

    Thanks anyway.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    68
    Rep Power
    12
    >Well, actually I meant writing a "find" code in C code...
    >Thanks anyway.
    Did you even look at the man page? It gives you a suite of C functions for reading and traversing directories. With those you can easily devise a recursive function to do what you want.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    4
    Rep Power
    0
    Originally posted by Kung Foo Master
    >Well, actually I meant writing a "find" code in C code...
    >Thanks anyway.
    Did you even look at the man page? It gives you a suite of C functions for reading and traversing directories. With those you can easily devise a recursive function to do what you want.
    OK I will try that. Thanks alot.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    4
    Rep Power
    0
    hmm... I still need help. Man code doesnt' say anything.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    68
    Rep Power
    12
    It says plenty, you just aren't reading into it enough. You'll find that the man pages contain pretty much everything you'll need for most situations. For example, by reading the man pages for opendir, readdir and closedir, I could come up with this to test their functionality:
    Code:
    #include <dirent.h> 
    #include <stdio.h> 
    
    int main(void)
    {
      DIR *d;
      struct dirent *dir;
    
      if ((d = opendir(".")) != NULL) {
        while ((dir = readdir(d)) != NULL)
          printf("%s\n", dir->d_name);
        closedir(d);
      }
    
      return 0;
    }

IMN logo majestic logo threadwatch logo seochat tools logo