[erlang-patches] Correct ls/1 in c.erl

Bengt Kleberg bengt.kleberg@REDACTED
Mon May 20 13:45:54 CEST 2013


6> file:list_dir("nosuchfile").
{error,enotdir}

I think to use file:read_link_info/1 to establish the existence of the
file/directory.


bengt

On Mon, 2013-05-20 at 11:00 +0200, Björn Gustavsson wrote:
> On Mon, May 20, 2013 at 10:49 AM, Bengt Kleberg
> <bengt.kleberg@REDACTED> wrote:
>         I will update the code and test suite according to you
>         suggestions.
>         
>         The failure to print /dev/null is due to filelib:is_file/1 not
>         thinking
>         of it as a file. I will change to another method.
> 
> 
> It seems to me that the simplest way would be like this:
> 
> 
>  ls(Dir) ->
>     case file:list_dir(Dir) of
> {ok, Entries} ->
>    ls_print(sort(Entries));
> {error, enotdir} ->
>    ls_print([Dir]);
> {error, Error} ->
>    format(file:format_error(Error))
>     end.
> 
> 
> (and deleting the ls_file/2 function.)
> 
> 
> Do you seen any problem with that method?
> 
> 
>         
> -- 
> Björn Gustavsson, Erlang/OTP, Ericsson AB




More information about the erlang-patches mailing list