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

Volker Wysk post at volker-wysk.de
Mon Oct 14 13:12:15 AEDT 2019


Am Montag, den 14.10.2019, 10:32 +1100 schrieb Julien Fischer:
> 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.)

I think those are overkill, when you just need the directory contents.
Maybe dir_contents should be added to the "dir" library?

Cheers,
Volker




More information about the users mailing list