[m-users.] Reading the entire directory contents (contribution for the posix library)

Julien Fischer jfischer at opturion.com
Mon Oct 14 10:32:20 AEDT 2019


Hi Volker,

On Fri, 11 Oct 2019, Volker Wysk wrote:

> Using opendir, readdir and closedir from the posix library, I've
> written a little code to read the entire contents of a directory.
>
> It's this predicate:
>
> :- pred dir_contents(
>       string::in,
>       posix.result(list(string))::out,
>       io::di, io::uo) is det.
>
> It takes the name of the directory and returns the contents of it.
>
> The contents are sorted, such that the "." and ".." entries are at thebeginning.
>
> I'd like to have this in the posix library.

I think this is outside the scope of what the POSIX binding was intended
to provide (i.e. a "bare" interface to POSIX functionality).

In any case, more general functionality for travesing over directories
is provided directly by the standard library (e.g. by the predicates
dir.foldl2/6 and dir.recursive_foldl2/7.)

Julien.


More information about the users mailing list