UNIX Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOperating SystemsUNIX Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old November 1st, 2003, 10:40 AM
SQ4LIFE SQ4LIFE is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 SQ4LIFE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
  #2  
Old November 1st, 2003, 01:42 PM
Kung Foo Master Kung Foo Master is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 68 Kung Foo Master User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Code:
$ man opendir

Reply With Quote
  #3  
Old November 2nd, 2003, 02:14 AM
SQ4LIFE SQ4LIFE is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 SQ4LIFE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
Originally posted by Kung Foo Master
Code:
$ man opendir


Well, actually I meant writing a "find" code in C code...

Thanks anyway.

Reply With Quote
  #4  
Old November 2nd, 2003, 02:26 PM
Kung Foo Master Kung Foo Master is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 68 Kung Foo Master User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
>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.

Reply With Quote
  #5  
Old November 2nd, 2003, 02:31 PM
SQ4LIFE SQ4LIFE is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 SQ4LIFE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Quote:
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.

Reply With Quote
  #6  
Old November 3rd, 2003, 12:07 PM
SQ4LIFE SQ4LIFE is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 4 SQ4LIFE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hmm... I still need help. Man code doesnt' say anything.

Reply With Quote
  #7  
Old November 3rd, 2003, 09:41 PM
Kung Foo Master Kung Foo Master is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 68 Kung Foo Master User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
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;
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsOperating SystemsUNIX Help > Writing "find" code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway