-module(tut).
-export([main/0]).
main() ->
folders("C:/Users/David/test/").
folders(PATH) ->
{_,DD} = file:list_dir(PATH),
A = [{H,filelib:is_dir(PATH ++ H)}|| H <-DD],
% R is a list of all folders inside PATH
R = [PATH++X|| {X,Y} <- A, Y =:= true],
io:fwrite("~p~n", [R]),
case R of
[] -> ok;
% How call again folders function with the first element of the list?
% And save the result in some kind of structure
end.
很抱歉问了初学者这个问题,但我对Erlang还是个新手。我想知道如何再次调用函数,直到将结果保存在一种列表、元组或结构中...
如:
[
{"C:/Users/David/test/log",
{"C:/Users/David/test/log/a", "C:/Users/David/test/log/b"}},
{"C:/Users/David/test/logb",
{"C:/Users/David/test/logb/1", "C:/Users/David/test/logb/2","C:/Users/David/test/logb/3"}},
]
1条答案
按热度按时间qnyhuwrf1#
Few things:
into
{Folder, [Subfolder1, Subfolder2, ...]}
, whereSubfolderX
will have the same definition and structure, recursively.lists:foldl
function.For consistency reason, you need to call the main function without a forward slash at the end, as this will be added in the function itself.
A helper function
pretty_print
below can be used to visualize the output on the Erlang shellFull code: