Finding the path to the file being executed


I am creating a install.jl script to install my software on my user’s computer: all necessary stuff is packed in a zip file, the user can unzip it into some folder Drive:\path, and is invited to execute Drive:\path\install.jl. install.jl will do some setting up. To that effect, I need my script to find out the value of “Drive:\path”. pwd() is not what I want, because it is not affected by executing a given file.

Any trick?




Take a look at @__FILE__ and @__DIR__:

help?> @__FILE__
  @__FILE__ -> AbstractString

  @__FILE__ expands to a string with the path to the file containing the
  macrocall, or an empty string if evaluated by julia -e <expr>. Returns
  nothing if the macro was missing parser source information. Alternatively

help?> @__DIR__
  @__DIR__ -> AbstractString

  @__DIR__ expands to a string with the absolute path to the directory of the
  file containing the macrocall. Returns the current working directory if run
  from a REPL or if evaluated by julia -e <expr>.


Spot on Frederik, thank you!