[erlang-questions] Retrieving priv directory path

Richard Carlsson carlsson.richard@REDACTED
Wed Oct 26 10:53:43 CEST 2011


On 10/26/2011 01:42 AM, 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.

And if someone moves your application to another directory relative to 
the working directory, this stops working. For example, if I include 
your application with another bunch of applications in a larger project 
and put all apps under ./lib/ relative to the top of my project from 
where I start erl. (As a general rule, don't rely on get_cwd, ever.)

 > So, how do you do it?

Set up your erlang code path properly also during development, so that 
it contains the application name. That is, not "erl -pa ebin", but "erl 
-pa ../myappname/ebin" (or use the full path, e.g., "erl -pa `pwd`/ebin").

    /Richard



More information about the erlang-questions mailing list