|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
Code:
$ man opendir |
|
#3
|
|||
|
|||
|
Quote:
Well, actually I meant writing a "find" code in C code... Thanks anyway. |
|
#4
|
|||
|
|||
|
>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. |
|
#5
|
|||
|
|||
|
Quote:
OK I will try that. Thanks alot. |
|
#6
|
|||
|
|||
|
hmm... I still need help. Man code doesnt' say anything.
|
|
#7
|
|||
|
|||
|
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;
}
|
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Writing "find" code |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|