# Should @\_\_DIR\_\_ give a path to the directory of the current file?

**URL:** <https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 11, 2021, 3:23am UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303 "2021-11-11T03:23:43Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [November 11, 2021, 3:23am UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303/1 "2021-11-11T03:23:43Z")

</div>

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

pwd() and @ **DIR** give the same result.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 11, 2021, 5:04am UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303/2 "2021-11-11T05:04:16Z")

</div>

[`https://docs.julialang.org/en/v1/base/base/#Base.@ __DIR__ `](https://docs.julialang.org/en/v1/base/base/#Base.@ __DIR__ )

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [November 11, 2021, 7:41am UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303/3 "2021-11-11T07:41:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [November 11, 2021, 10:55pm UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303/5 "2021-11-11T22:55:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 12, 2021, 3:09am UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303/6 "2021-11-12T03:09:29Z")

</div>

I use

```julia
function campaign_directory()
    return dirname(@ __FILE__ ())
end

```

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

---

<div class="post-metadata">

**Author:** ![BMval](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bmval/32/7647_2.png) [@BMval](https://discourse.julialang.org/u/BMval)\
**Post date:** [November 12, 2021, 3:22am UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303/7 "2021-11-12T03:22:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 12, 2021, 3:33am UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303/8 "2021-11-12T03:33:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [November 12, 2021, 4:43am UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303/9 "2021-11-12T04:43:28Z")

</div>

Here is how it works for me: ![ScreenHunter-04](https://global.discourse-cdn.com/julialang/original/3X/1/2/1215ff31d388b12840c7f4601d99721c69504731.gif)
