Skip to content

Instantly share code, notes, and snippets.

@flashingpumpkin
Created August 28, 2011 23:30
Show Gist options
  • Select an option

  • Save flashingpumpkin/1177390 to your computer and use it in GitHub Desktop.

Select an option

Save flashingpumpkin/1177390 to your computer and use it in GitHub Desktop.
normpath(Path) ->
filename:join(normpath(filename:split(Path), [])).
normpath([], Acc) ->
lists:reverse(Acc);
normpath([".." | Rest], [Prev|Acc]) ->
normpath(Rest, Acc);
normpath([Head|Rest], Acc) ->
normpath(Rest, [Head|Acc]).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
normpath_test()->
?assertEqual("/home/foo", normpath("/home/bar/../foo")),
?assertEqual("/etc/foo", normpath("/home/bar/../../etc/foo")).
-endif.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment