[m-users.] Reading the entire directory contents (contribution for the posix library)
Volker Wysk
post at volker-wysk.de
Mon Oct 14 17:50:52 AEDT 2019
Am Montag, den 14.10.2019, 13:57 +1100 schrieb Julien Fischer:
>
> On Mon, 14 Oct 2019, Zoltan Somogyi wrote:
>
> > On Mon, 14 Oct 2019 13:37:51 +1100 (AEDT), Julien Fischer <
> > jfischer at opturion.com> wrote:
> > > > Maybe dir_contents should be added to the "dir" library?
> > >
> > > I'm not convinced that it is generally useful enough to warrant
> > > inclusion it the standard library.
> >
> > I think it is useful enough.
>
> I disagree, returning the directory contents in a particular order
> seems quite application specific. Why just return their names?
> In many circumstances you would presuambly be interested in what
> kind of file each entry is as well.
>
> OTOH, if others feel strongly that this is something that should
> be in the stdlib, then I suggest the following:
>
> % contents(DirName, Result, !IO):
> % Return the entries of the directory DirName sorted according
> % to the standard order for strings.
> %
> :- pred contents(string::in,
> io.maybe_partial_result(list(string))::out, io::di, io::uo)
> is det.
>
> % contents(CmpPred, DirName, Result, !IO):
> % Return the entries of the directoryDirName sorted according
> % to CmpPred.
> %
> :- pred contents(comparison_pred(string)::in(comparison_pred)
> string::in, io.maybe_partial_result(list(string))::out,
> io::di, io::uo) is det.
This still introduces complexity (less, but still), which won't be
needed most of the time.
I suggest adding a front end to your contents() predicates, which is
just:
:- pred contents(string::in, list(string)::out, io::di, io::uo).
Cheers,
Volker
More information about the users
mailing list