Handling relative paths inside my mix project

Trying to read/write from a csv file for my project.

This works in the console.

iex> File.write("../../csv/rank.csv", content)

But the same code in my app does not (returns enoent). I’ve read you should avoid using hard-coded paths, so what’s the best way to handle reading/writing to plain or media files ?

1 Like

Generally the priv directory is where system file reads and writes happen. Theres even an erlang function for getting the path in Elixir you call it with :code.priv_dir(:my_application_name). The application name is the name from your mix.exs file. So each application has it’s own priv directory. The priv_dir function works in iex and in releases.

2 Likes