Page 1 of 1
Relative pathways
Posted: Tue Jan 28, 2025 11:54 pm
by JC198998
Hello,
I need advice on applying relative pathways in program files.
I have several program files. They're structured in a way where I have one primary program file that calls on several supplementary program files (which do things like import/export excel files). All of them have the same path (or are in the same folder), but because they're hardcoded, I have to change the pathway of each of the program files.
Is there a way I can put the pathway just once in the primary program file and have the supplementary program files adopt the same pathway specified in the primary program file?
Thank you for your time.
Re: Relative pathways
Posted: Wed Jan 29, 2025 8:38 am
by EViews Gareth
Re: Relative pathways
Posted: Thu Jan 30, 2025 9:24 am
by JC198998
Thank you for this.
I may need a bit more help though if it is all right.
Say I have two program files (1) primary.prg and (2) secondary.prg in the folder "C:\Documents\Main Directory".
How do I get (2) secondary.prg to adopt the same path specified in (1) primary.prg?
For example, if
(1) primary.prg has the following path which the secondary program file adopts:
Code: Select all
'Primary program file
%main_directory = "C:\Documents\Main Directory\"
How do I get
(2) secondary.prg to adopt something like:
Code: Select all
Secondary program file
excel_final_path = %main_directory + "Data_files\Excel.xlsx"
import %excel_file_path range = "Sheet1 A1:BG100" @freq m 2000M01
How would I get the secondary.prg to use the file path specified in the primary.prg?
Thank you for your time.
Re: Relative pathways
Posted: Thu Jan 30, 2025 10:03 am
by EViews Gareth
How are primary and secondary related? How are they interacting with each other?
Re: Relative pathways
Posted: Thu Jan 30, 2025 9:11 pm
by JC198998
Yes, the primary program mainly calls on the secondary program file to run operations like importing excel files, running models, equations.
For example, you will see lines like in the primary program file:
Code: Select all
subroutine inputs
%main_directory = "C:\Documents\Main Directory\"
%BEGQ="1990Q1" 'Start
%ENDQ="2000Q4" 'End
endsub
%secondary_file = %main_directory + "secondary.prg"
call inputs
include %secondary_file
Re: Relative pathways
Posted: Fri Jan 31, 2025 9:35 am
by EViews Gareth
Since you are using an include statement, the secondary program will have access to your %main_directory variable.
Re: Relative pathways
Posted: Sat Feb 08, 2025 10:31 am
by JC198998
Hi Gareth, thanks for this response and apologies for the late follow up.
But every time I try to run include %secondary.prg, I get an error saying the file doesn't exist because the code seems to read %secondary.prg as string and not its actual definition. Would you know a way around this?
Re: Relative pathways
Posted: Sat Feb 08, 2025 12:07 pm
by EViews Gareth
Ah, sorry, yes, forgot. You can’t use string variables with an include.