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

Julien Fischer jfischer at opturion.com
Mon Oct 14 13:57:59 AEDT 2019



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.

Julien.


More information about the users mailing list