# Why do hitting Ctrl+Enter or cutting and pasting code in the REPL yield different results?

**URL:** <https://discourse.julialang.org/t/why-do-hitting-ctrl-enter-or-cutting-and-pasting-code-in-the-repl-yield-different-results/104272>\
**Category:** Performance\
**Tags:** question\
**Created:** [September 26, 2023, 4:00pm UTC](https://discourse.julialang.org/t/why-do-hitting-ctrl-enter-or-cutting-and-pasting-code-in-the-repl-yield-different-results/104272 "2023-09-26T16:00:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soldalma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/soldalma/32/29388_2.png) [@Soldalma](https://discourse.julialang.org/u/Soldalma)\
**Post date:** [September 26, 2023, 4:00pm UTC](https://discourse.julialang.org/t/why-do-hitting-ctrl-enter-or-cutting-and-pasting-code-in-the-repl-yield-different-results/104272/1 "2023-09-26T16:00:44Z")

</div>

I have some code that I am working on in VSCode, where at some point I try to include a file with this line:

```julia
include("./src/ModelData.jl")

```

Then I get an error message:

```julia
ERROR: SystemError: opening file "c:\\Users\\fsald\\Dropbox\\Code\\Julia\\bootstrapwalkforward\\BWModule\\src\\src\\ModelData.jl": No such file or directory

```

The problem is the `src\\src` in the path. The true path has only one `src`. When I hit `pwd()` on the REPL I get a path that does not include `src` at the end. If I write `pwd()` in the editor, select that line, and hit Ctrl+Enter I get the same exact path, without `src` at the end.

Selecting that line and hitting Ctrl+Enter generates the same error.

However, if I cut and paste that exact same line on the REPL the code runs fine.

This is a problem as when I am working on the code sometimes after selecting a code bit I hit Ctrl+Enter and other times I copy that code and paste it on the REPL.

I would like to understand the reason for this difference in behavior, so that perhaps I can make the behavior uniform when I hit Ctrl+Enter or when I cut and paste code on the REPL.

Any ideas?

---

<div class="post-metadata">

**Author:** ![alfaromartino](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alfaromartino/32/52986_2.png) [@alfaromartino](https://discourse.julialang.org/u/alfaromartino)\
**Post date:** [September 26, 2023, 5:24pm UTC](https://discourse.julialang.org/t/why-do-hitting-ctrl-enter-or-cutting-and-pasting-code-in-the-repl-yield-different-results/104272/2 "2023-09-26T17:24:16Z")

</div>

I didn’t know the notation `.` in a file path, and it gives me an error in my computer. Are you trying to use `"$(homedir())"`.

Notice that, if you work with commands that handle files, the output could change depending on whether you write the prompt in the REPL or with ctrl+enter. For instance, `@ __FILE__ ` provides the path to the file. But if you’re in the REPL, you aren’t working in a specific file and it’ll return `"REPL[7]"`. Instead, pressing ctrl+enter will return the name of the file from which you’re executing it.

Don’t know if all this helps.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [September 26, 2023, 5:32pm UTC](https://discourse.julialang.org/t/why-do-hitting-ctrl-enter-or-cutting-and-pasting-code-in-the-repl-yield-different-results/104272/3 "2023-09-26T17:32:09Z")

</div>

The `.` in the `./src` notation is a “relative” path — the question is relative to what? At the REPL it’s relative to your current working directory. When Julia is executing a file, it’s relative to the file it’s currently executing.

When you execute a line of code with control-enter, VS Code is choosing to make it relative to the file you’re in so it matches the behavior of Julia itself.

---

<div class="post-metadata">

**Author:** ![Soldalma](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/soldalma/32/29388_2.png) [@Soldalma](https://discourse.julialang.org/u/Soldalma)\
**Post date:** [September 26, 2023, 9:00pm UTC](https://discourse.julialang.org/t/why-do-hitting-ctrl-enter-or-cutting-and-pasting-code-in-the-repl-yield-different-results/104272/4 "2023-09-26T21:00:19Z")

</div>

Explains perfectly what was happening. I guess I will use cd(“./src”) to change my working directory to be the same as the directory the file I am executing is in. After that it should make no difference whether I paste code on the REPL or select the code on the editor and hit Ctrl+Enter.
