I've been trying to set the default working directory in VS Code, when a workspace is not open, to the directory where the file being executed is. This is the normal behaviour in other IDEs, like Python IDlE. I need this so my students can run a program from whatever folder they have it in, and it can open files referred to by their program using relative reference. They always have the file in the same directory as the running file (for example an MP3 that they want to open during their program).
I've read for hours lots of documentation, both in VS Code and Stackoverflow, without success.
I know that setting a workspace to that folder will solve it, but is not a viable solution for us, as they will be opening files from different locations all of the time.
I've tried changing the terminal.integrated.cwd in the settings.json file to take by default the directory where the file being executed is (like in IDlE), without success. I can't find the string that I need to include in terminal.integrated.cwd for this. I've tried the following strings ".", ".", ".\", ""
I've also tried this:
"terminal.integrated.cwd": "${fileDirname}"
But when I run the following piece of code to see if the working directory has changes, after reset of VS code:
import os
cwd = os.getcwd()
print("Current working directory: {0}".format(cwd))
It still shows me the working directory as c:\users\my_user_name And not the one where the file running this code is.
Could someone please tell me what can I do next? Thank you.