[erlang-questions] Fast directory walker

Frank Muller frank.muller.erl@REDACTED
Sat Dec 10 00:15:58 CET 2016


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,ok}

The idea behind it is to build something similar to The Platinum Searcher
(in Go, extremely fast):
https://github.com/monochromegane/the_platinum_searcher

Advices very appreciated on how to improve its speed.

/Frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20161209/25b1886a/attachment.htm>


More information about the erlang-questions mailing list