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

Yao Bao free7by@REDACTED
Thu Jul 1 02:28:49 CEST 2021


By exploring the source code, I found file:list_dir/1 is implemented as a NIF, which is implemented in C.
And, under UNIX, it uses opendir() and readdir() to get the directory entries, dot(.) and dot-dot(..) is ignored by design.

The specified source code is here (efile_list_dir and is_ignored_name): <> <>

But no comment saying why dot(.) and dot-dot(..) is ignored.


> 在 2021年6月29日,08:29,Yao Bao <free7by@REDACTED> 写道:
> Hello,
> I'm trying to list all files in a directory, then I found file:list_dir/1, it works fine but dot(.) and dot-dot(..) is missing.
> I would expect the result from file:list_dir/1 in Erlang is the same as readdir(dirp) in C.
> Is there any (historical) reason why these two special directories missing from the return?
> Cheers,
> Yao

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the erlang-questions mailing list