Should @__DIR__ give a path to the directory of the current file?

should @DIR give a path to the directory of the current file?

pwd() and @DIR give the same result.

1 Like

If Julia is running code in a file, @__FILE__ should give you the full path to that file and @__DIR__ should equal dirname(@__FILE__). If you are running code directly in the REPL, @__DIR__ should give you the same result as pwd() and @__FILE__ will (*) give you a string indicating you are running from the REPL. If you are evaluating code in some IDE you need to consult its documentation to find out how it does that or at least tell us what environment you are working in.

(*) The docstring isn’t very clear on what @__FILE__ is expected to do from the REPL, what I wrote above is the observed behavior in Julia 1.6.

1 Like

Thank you for the link.

Thank you everybody for your answers.

So what do you suggest to me, how to get a path to the directory of the current file, If I run code in VS? Unfortunately, @_ DIR _ doesn’t help.

I use

function campaign_directory()
    return dirname(@__FILE__())

in the file campaign_directory.jl. Whenever I run this from, the directory of the campaign is correctly deduced.

I run this code at VS, Unfortunately, it gives an empty string.

Oh, I use Sublime Text, and it works fine. I will check with VS Code.

Here is how it works for me: ScreenHunter-04

1 Like