file:list_dir/1 cannot lists dot(.) and dot-dot(..) directories

Nicolas Martyanoff khaelin@REDACTED
Tue Jun 29 09:09:03 CEST 2021


Ivan Uemlianin <ivan@REDACTED> writes:

> Python doesn't include '.' or '..' either:
>
>>>> import os
>>>> '.' in os.listdir()
> False
>>>> '..' in os.listdir()
> False
>
> Although you are able use them for example to list the content of a directory:
>
>>>> x = os.listdir()
>>>> os.chdir('..')
>>>> x == os.listdir()
> False
>
> Erlang's behaviour is similar:
>
> 1> {ok, Fs} = file:list_dir(D).
> {ok,[<filenames>]}
> 2> lists:member(".", Fs).
> false
> 3> lists:member("..", Fs).
> false
>
> 4> file:list_dir("..").
> {ok,[<filenames>]}
>

Ah yes, my bad; . and .. should be usable as any other file, but
including them when listing directories is a matter of preference.

-- 
Nicolas Martyanoff
http://snowsyn.net
khaelin@REDACTED


More information about the erlang-questions mailing list