Getting the name of the script that is being executed

Say my command line input is
$> elixir test.exs 1 2 3

I know i can use System.argv to get the argument variable but how can i also get the name of the script “test.exs” ?

To reply my own question and share with those who wants to know. You can use __ENV__.file

This will give you the fullpath though, i just need the filename with extension.

1 Like

Path.basename(__ENV__.file) will give you what you want. (If you have not figured it out yet).

1 Like

Hey thanks man, that a lot more slick than __ENV__.file |> String.split("/") |> List.last

1 Like

yes and will work on Windows (your solution will not)

1 Like

Good point

1 Like