question about intended function of filelib:wildcard/2
Vlad Dumitrescu
vlad_dumitrescu@REDACTED
Tue Apr 12 20:33:25 CEST 2005
> filelib:wildcard("/home/eleberg/*").
> filelib:wildcard("*", "/home/eleberg").
> on my system they return very different lists.
>
> could somebody please explain if they should be different, and how
> wildcard/2 is supposed to be used.
Hi,
Looking at the code,
wildcard(Pattern) ->
{ok, Cwd} = file:get_cwd(),
wildcard(Pattern, Cwd).
wildcard({compiled_wildcard, [Base|Rest]}, _Cwd) ->
wildcard1([Base], Rest);
wildcard(Pattern, Cwd) when list(Pattern), list(Cwd) ->
wildcard(compile_wildcard(Pattern), Cwd).
it's interesting to notice that the Cwd argument is not used at all.
I would suppose that the intention was that if Base was a relative path, it
should be appended to Cwd. If Base is absolute, then Cwd should be ignored,
of course.
Using for example
wildcard({compiled_wildcard, [Base|Rest]}, Cwd) ->
case filename:pathtype(Base) of
relative ->
wildcard1([join(Base, Cwd)], Rest);
_ ->
wildcard1([Base], Rest)
end;
works, with the only drawback that the returned filenames are all absolute
(which might or might not be what one needs).
regards,
Vlad
More information about the erlang-questions
mailing list