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

Ivan Uemlianin ivan@REDACTED
Tue Jun 29 08:57:30 CEST 2021


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>]}

Ivan


On 29/06/2021 07:31, Nicolas Martyanoff wrote:
> Vimal Kumar <vimal7370@REDACTED> writes:
>
>> I am not sure if any programming language (let alone Erlang) does that
>> while listing folder contents. The . and .. are mere references to current
>> folder and the parent folder by the OS, they does not exist in real if I am
>> not wrong.
> Other programming languages handle it as expected, e.g. in Ruby:
>
>      Dir.entries(".")
>
> On UNIX, . and .. are indeed no real files, but they behave as
> hardlinks. Not being able to use them for example to list the content of a
> directory is indeed a bug.
>

-- 
============================================================
Ivan A. Uemlianin PhD
Llaisdy

Ymchwil a Datblygu Technoleg Lleferydd
Speech Technology Research and Development

                     ivan@REDACTED
                         @llaisdy
                          llaisdy.wordpress.com
               github.com/llaisdy
                      www.linkedin.com/in/ivanuemlianin

                         festina lente
============================================================



More information about the erlang-questions mailing list