Starting Julia debugger in a given directory

I’m writing a script that read files in the same folder that contains the script itself. So the script starts with something like

let wfn_file_name = "WFN_co.h5",
    eqp_file_name = "eqp_co.dat",
    itrs_max = 1

    wfn_fid = h5open(wfn_file_name)
    eqp_fid = open(eqp_file_name)
#...

And now I want to debug it. The script is not in the root directory of the current VSCode workspace, which however is set to be the default working directory of Julia debugger in VSCode. Therefore the program fails (pause at exception) the time it reaches h5open(...).

Is there any way to tell the debugger to start in the folder that directly contains my script? Another solution is to let the program stop before h5open and then I manually set the working directory using cd in DEBUG CONSOLE.

Of course, I can change the wfn_file_name etc. when debugging, but at the risk of forgetting to change them back after debugging; and it’s also very inconvenient.

I think that should be a quite common problem. What are your solutions when you face this simple but annoying issue?

You can specify paths relative to the file where the code is written using

joinpath(@__DIR__, "other_file_next_to_source.csv")

Source: Essentials · The Julia Language

2 Likes