[erlang-questions] Fast directory walker
Michael Truog
mjtruog@REDACTED
Sat Dec 10 03:12:19 CET 2016
On 12/09/2016 03:15 PM, Frank Muller wrote:
> Hi
>
> I would like to improve the speed of my directory walker.
>
> walk(Dir) ->
> {ok, Files} = prim_file:list_dir(Dir),
> walk(Dir, Files).
>
> walk(Dir, [ Basename | Rest ]) ->
> Path = filename:join([ Dir, Basename ]),
> case filelib:is_dir(Path) of
> true ->
> walk(Path);
> false ->
> io:format("~s~n", [Path]),
> filelib:file_size(Path)
> end,
> walk(Dir, Rest);
> walk(_, []) ->
> ok.
>
>
> Compared to almost anything i found on the web, it’s still very slow:
> > timer:tc(fun() -> dir:walk("/usr/share") end).
> {4662361 <tel:4662361>,ok}
Have you tried filelib:fold_files/5 (http://erlang.org/doc/man/filelib.html#fold_files-5) ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161209/31f8b295/attachment.htm>
More information about the erlang-questions
mailing list