Re: A function for ls?



On Fri, Feb 23, 2001 at 04:24:04PM +0100, Germano Rizzo wrote:
> Hi!
>     is there a library function that gives the contents of a directory?
> Something like 'ls'... or a way to do it using other functions? At least,
> may you address me to a program that uses such a function, to learn on it? I
> browsed the source of ls, but it's... too much! ;)

Yes there is, but (obviously, being a system call) it's not
portable.

The POSIX way to do it is to use operdir(), dirent(), rewinddir()
and closedir(). These should all be in section 2 of your man
pages... chdir() and fchdir() can be used to change directories,
and then normal file i/o operations can be used once you have the
file(s) you want.

>     Mano :)

Cheers,
Dave.

-- 
  .------------------------------.
 /          David Neary,          \
|     E-Mail dneary eircom net     | 
 \     Phone +353-1-872-0654      /
  `------------------------------'




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]