tres
tres

Reputation: 1480

How To Get The Root Directory Of an Elixir Project

In an Elixir project, you can use

Path.expand

to define a file or directory as a relative path from the current file.

For example: Path.expand("../../../lib/file.ex")

but how about finding a path from the root level of the project?

Upvotes: 24

Views: 13007

Answers (2)

Istopopoki
Istopopoki

Reputation: 1762

In case of an umbrella app, you can create a key in your config.exs file :

config :some_app,
  project_root: File.cwd!

And then use that value from wherever you want in your project :

project_root = Application.fetch_env!(:some_app, :project_root)

Upvotes: 5

tres
tres

Reputation: 1480

If you'd like to get the project's root directory, use

File.cwd!

source: https://groups.google.com/d/topic/elixir-lang-talk/Ls0eJDdMMW8

(note: I pulled this here only so it's not buried in a dead forum behind Google auth wall & subject to Google data preservation policies)

Upvotes: 32

Related Questions