Page 1 of 1

change default directory

Posted: Mon Sep 27, 2021 2:19 am
by QIO
I am trying to build a separate sub routine library that I can call later via “include”;
for “include” to work I need to change the default directory, this, however, simply does not work and when executing the following execution.prg it will give me an error message that the sub (called here static_system) is not in the folder (which it is);
the problem is that it searches in the folder where this execution.prg is located and not where I have put the change directory call

why is this the case? thx!
M

Code: Select all

cd "C:\users\default\OneDrive\work"
include static_system

Re: change default directory

Posted: Mon Sep 27, 2021 8:18 am
by EViews Steve
Internally, all includes in a program are performed BEFORE the program is actually run. So having an include that depends on a previous call to CD won't work. Our docs actually mention this by saying INCLUDE only uses current program folder, not the current working directory.

While not ideal, you should either use explicit paths to your included programs or use multiple copies of your initial program in each of the different folders you want to run from. The initial program could just be a list of includes that use relative paths to bring in all related programs under the current folder.

Re: change default directory

Posted: Wed Sep 29, 2021 12:16 am
by QIO
hi Steve
thx very much for your quick answer -

Code: Select all

include "C:\users\default\OneDrive\work\static_system.prg"
seems to work fine and solves the problem;
best greetings
Michael