# Use @\_\_FILE\_\_ in pasted code in REPL

**URL:** <https://discourse.julialang.org/t/use-file-in-pasted-code-in-repl/55824>\
**Category:** General Usage\
**Tags:** question\
**Created:** [February 23, 2021, 6:17am UTC](https://discourse.julialang.org/t/use-file-in-pasted-code-in-repl/55824 "2021-02-23T06:17:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [February 23, 2021, 6:17am UTC](https://discourse.julialang.org/t/use-file-in-pasted-code-in-repl/55824/1 "2021-02-23T06:17:46Z")

</div>

I no longer use Atom or VSCode. My current workflow is to send codes on a Julia script to an open Julia REPL. I want to set the current folder to be my working directory. Using `cd(dirname(@ __FILE__ ))` in this manner does not work. What should I do?

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [February 23, 2021, 6:57am UTC](https://discourse.julialang.org/t/use-file-in-pasted-code-in-repl/55824/2 "2021-02-23T06:57:49Z")

</div>

> [@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 …

first result if you search “FILE macro REPL”. Please search before posting, especially that was very much recently asked.

---

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [February 23, 2021, 6:59am UTC](https://discourse.julialang.org/t/use-file-in-pasted-code-in-repl/55824/3 "2021-02-23T06:59:30Z")

</div>

I am aware of this, that’s why I am asking if there is an alternative solution. I prefer to make my code portable.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [February 23, 2021, 7:00am UTC](https://discourse.julialang.org/t/use-file-in-pasted-code-in-repl/55824/4 "2021-02-23T07:00:15Z")

</div>

does `pwd()` or `@ __DIR__ ` not work for you?

---

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [February 23, 2021, 7:02am UTC](https://discourse.julialang.org/t/use-file-in-pasted-code-in-repl/55824/5 "2021-02-23T07:02:58Z")

</div>

no.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [February 23, 2021, 7:11am UTC](https://discourse.julialang.org/t/use-file-in-pasted-code-in-repl/55824/6 "2021-02-23T07:11:30Z")

</div>

I re-read your question. You’re sending code of a script lying somewhere (in a copy-paste manner) to an REPL session.

This is like copying a snippet of text from some random file and pasting into REPL and expect REPL to know which file you copied the code from.

* * *

In this case, there’s no easy way around unless the tool you’re using has some way to send the file path to Julia REPL. What tool are you using exactly?

---

<div class="post-metadata">

**Author:** ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)\
**Post date:** [February 23, 2021, 7:18am UTC](https://discourse.julialang.org/t/use-file-in-pasted-code-in-repl/55824/7 "2021-02-23T07:18:16Z")

</div>

I am using RStudio. I think you are right. The Julia REPL has no way to know where the pasted codes come from.
