[erlang-questions] Retrieving priv directory path

Garrett Smith <>
Wed Oct 26 06:50:26 CEST 2011


Hi Nikola,

On Tue, Oct 25, 2011 at 6:42 PM, Nikola Skoric <> wrote:
> What would be universal way to get priv dir path?
>
> Currently I retrieve priv dir like this:
>
> priv_dir(App) ->
>    case code:priv_dir(App) of
>        {error, bad_name} ->
>            {ok, Cwd} = file:get_cwd(),
>            Cwd ++ "/" ++ "priv/";
>        Priv ->
>            Priv ++ "/"
>    end.
>
> First case is when I develop code, it does not work when I make a
> release. When I make a release, core:priv_dir returns {error,
> bad_name} because application:get_application returns something that
> core:priv_dir doesn't agree with.
>
> So, how do you do it?

I use this:

priv_dir(Mod) ->
    Ebin = filename:dirname(code:which(Mod)),
    filename:join(filename:dirname(Ebin), "priv").

Garrett



More information about the erlang-questions mailing list