Use @__FILE__ in pasted code in REPL

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?

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

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

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

no.

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?

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