# How to get the path of a Julia script

**URL:** <https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728>\
**Category:** General Usage\
**Created:** [January 27, 2017, 9:41pm UTC](https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728 "2017-01-27T21:41:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![willow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willow/32/208918_2.png) [@willow](https://discourse.julialang.org/u/willow)\
**Post date:** [January 27, 2017, 9:41pm UTC](https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728/1 "2017-01-27T21:41:17Z")

</div>

I have found a small inconsistency in the google group lists. When you type “julia get directory of script” into a google search box (finding a way to programmatically determine the file path of the currently executing source code), you get this answer: [Redirecting to Google Groups](https://groups.google.com/forum/#!topic/julia-users/BSQfu9mmoL0)

However, this method fails if you call it from code that gets passed into a macro in another file. I had this problem when I used Base.source\_path() in a function that was called from within a testset. However, @ **FILE** does not have this problem. I wanted to suggest this to the user on the google group, but it is locked, so I decided to tell you.

Minimal example of what I mean:

foo.jl:

```julia
function foo()
  println(Base.source_path())
end

```

bar.jl:

```julia
include("foo.jl")
using Base.Test
@testset "my_testset" begin
  foo()
end

```

Anyways, maybe this is the desired behavior of Base.source\_path(), but I was confused at the behavior I saw given the description given in the google group.

So, for new julia users directed here from google, to get the path of the currently executing file, you should use @ **FILE**. Somebody please correct me if I’m wrong.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 28, 2017, 8:36am UTC](https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728/2 "2017-01-28T08:36:34Z")

</div>

The google group is (was) a mailing list, not documentation. Documentation can be found at [http://docs.julialang.org/en/latest/](http://docs.julialang.org/en/latest/). I think it is possible that you are looking for [Base.PROGRAM\_FILE](http://docs.julialang.org/en/latest/stdlib/constants.html#Base.PROGRAM_FILE).

---

<div class="post-metadata">

**Author:** ![willow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/willow/32/208918_2.png) [@willow](https://discourse.julialang.org/u/willow)\
**Post date:** [January 28, 2017, 3:12pm UTC](https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728/3 "2017-01-28T15:12:24Z")

</div>

I understand that the google group was not documentation. However, like stackoverflow, it is actually what curious new users like me find when they google documentation questions. I just wanted to put something on the web on the right forum to correct what I found.

Base.PROGRAM\_FILE is not what I want because it does not give the full path, and in fact suffers from the same issue that Base.source\_path does when used in a macro. Try it in my example!

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [May 31, 2018, 11:46am UTC](https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728/4 "2018-05-31T11:46:49Z")

</div>

Thanks the pointer to `@ __FILE__ ` was very useful. (` __@DIR__ ` is also very useful FWIW)

---

<div class="post-metadata">

**Author:** ![Errazuriz](https://avatars.discourse-cdn.com/v4/letter/e/b38774/32.png) [@Errazuriz](https://discourse.julialang.org/u/Errazuriz)\
**Post date:** [October 6, 2018, 7:19pm UTC](https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728/5 "2018-10-06T19:19:24Z")

</div>

Thank you for the info, very useful.

---

<div class="post-metadata">

**Author:** ![rakeshvar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rakeshvar/32/3613_2.png) [@rakeshvar](https://discourse.julialang.org/u/rakeshvar)\
**Post date:** [April 30, 2019, 8:53pm UTC](https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728/6 "2019-04-30T20:53:10Z")

</div>

`@ __DIR__ ` (The @ is in the wrong place above.)

---

<div class="post-metadata">

**Author:** ![Juksu](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@Juksu](https://discourse.julialang.org/u/Juksu)\
**Post date:** [June 15, 2021, 8:30am UTC](https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728/7 "2021-06-15T08:30:53Z")

</div>

Dead link to Base.PROGRAM\_FILE, use instead:  
[https://docs.julialang.org/en/v1/base/constants/#Base.PROGRAM\_FILE](https://docs.julialang.org/en/v1/base/constants/#Base.PROGRAM_FILE)

---

<div class="post-metadata">

**Author:** ![Realife\_Brahmin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/realife_brahmin/32/50796_2.png) [@Realife\_Brahmin](https://discourse.julialang.org/u/Realife_Brahmin)\
**Post date:** [November 2, 2023, 2:29am UTC](https://discourse.julialang.org/t/how-to-get-the-path-of-a-julia-script/1728/8 "2023-11-02T02:29:02Z")

</div>

> [@rakeshvar](#):
>
> `@ __DIR__ ` (The @ is in the wrong place above.)

correct.
