Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Get The Root Directory Of an Elixir Project

Tags:

elixir

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?

like image 603
tres Avatar asked Aug 28 '17 00:08

tres


2 Answers

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)

like image 101
tres Avatar answered Nov 08 '22 14:11

tres


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)
like image 44
Istopopoki Avatar answered Nov 08 '22 15:11

Istopopoki