Is this code tail recursive ?

Radu Brumariu <>
Mon Feb 7 00:08:57 CET 2011


gather_files([]) -> [];
gather_files(F) ->
    gather_files(F,[]).
gather_files([],[Acc]) -> Acc;
gather_files([{path,F}|Files],Acc) ->
    io:format("Processing path ~p~n",[F]),
    {ok, T} = file:read_file_info(F),
    case T#file_info.type
    of
	regular ->
	    gather_files(Files, [F | Acc]);
	directory ->
	    gather_files(Files, [gather_directory_files(F) | Acc ]);
	_ ->
	    gather_files(Files, Acc)
    end.

gather_directory_files(D) ->
    filelib:fold_files( D, ".*", true, fun(X,Acc) ->
				        [X|Acc]
			       end,
		       []).


If not, how can it be rewritten ?

Thanks,
Radu


More information about the erlang-questions mailing list