# Julia Source Code Directory

**URL:** <https://discourse.julialang.org/t/julia-source-code-directory/64904>\
**Category:** New to Julia\
**Created:** [July 19, 2021, 4:45am UTC](https://discourse.julialang.org/t/julia-source-code-directory/64904 "2021-07-19T04:45:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nelson\_Chow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nelson_chow/32/27288_2.png) [@Nelson\_Chow](https://discourse.julialang.org/u/Nelson_Chow)\
**Post date:** [July 19, 2021, 4:45am UTC](https://discourse.julialang.org/t/julia-source-code-directory/64904/1 "2021-07-19T04:45:02Z")

</div>

Hi, I am new to Julia, previously work primarily on VBA, a little C++, Matlab and Python.

This is literally my second Julia Script after Hello World.

I was wondering (and i have searched on google and this forum already) , how do I get the directory of my current script?

I have VSCode installed on Windows 10  
I have tried pwd() and base.source\_dir() , however both are listing my user’s home directory instead of my script directory

My script is stored under: C:\Users\nelso\Documents\Julia\myscript.jl  
When using pdw() or base.source\_dir(), Julia returns "C:\Users\nelso"

What do i have to do for Julia to give me "C:\Users\nelso\Documents\Julia"

Thanks  
Nelson

---

<div class="post-metadata">

**Author:** ![findmyway](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/findmyway/32/4946_2.png) [@findmyway](https://discourse.julialang.org/u/findmyway)\
**Post date:** [July 19, 2021, 4:49am UTC](https://discourse.julialang.org/t/julia-source-code-directory/64904/2 "2021-07-19T04:49:38Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![Nelson\_Chow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nelson_chow/32/27288_2.png) [@Nelson\_Chow](https://discourse.julialang.org/u/Nelson_Chow)\
**Post date:** [July 19, 2021, 4:55am UTC](https://discourse.julialang.org/t/julia-source-code-directory/64904/3 "2021-07-19T04:55:53Z")

</div>

Hi Findmyway,

I have followed your lead and use println(@ **DIR** ) , but I got:

“C:\users\nelso”  
instead of  
“C:\users\nelso\Documents\Julia” which I want (where the myscript.jl is stored)

any more clues?

THanks again  
Nelson

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [July 19, 2021, 5:03am UTC](https://discourse.julialang.org/t/julia-source-code-directory/64904/4 "2021-07-19T05:03:46Z")

</div>

You’re probably looking for `@ __FILE__ `. Check the REPL help mode (enter `?` and then whatever you want to look up) or the [docs](https://docs.julialang.org/en/v1/base/base/#Base.@ __FILE__ ) for more information.

---

<div class="post-metadata">

**Author:** ![Nelson\_Chow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nelson_chow/32/27288_2.png) [@Nelson\_Chow](https://discourse.julialang.org/u/Nelson_Chow)\
**Post date:** [July 19, 2021, 5:32am UTC](https://discourse.julialang.org/t/julia-source-code-directory/64904/5 "2021-07-19T05:32:53Z")

</div>

Thanks Team,

Looking at another thread,

> [@The macrocall @\_\_FILE\_\_ does not return the directory of the file, but rather the REPL output number](https://discourse.julialang.org/t/the-macrocall-file-does-not-return-the-directory-of-the-file-but-rather-the-repl-output-number/55585):
>
> I have been using to following to change my working directory to the location of my .jl scripts in Atom as follows without problems: cd(dirname(@\_\_FILE\_\_)) When I run a script with this in vs code, I get an error and it doesn’t change my working directory: julia\> cd(dirname(@\_\_FILE\_\_)) ERROR: IOError: chdir : invalid argument (EINVAL) Stacktrace: [1] uv\_error at .\libuv.jl:97 [inlined] [2] cd(::String) at .\file.jl:84 [3] top-level scope at REPL[2]:1 The reason that is I think is because …

using ctrl-enter will yield what i get, and using alt-enter is a better way to execute code, and get what i actually want.

Cheers,  
take care  
Nelson
