Relative pathways

For requesting general information about EViews, sharing your own tips and tricks, and information on EViews training or guides.

Moderators: EViews Gareth, EViews Moderator

JC198998
Posts: 13
Joined: Thu Jan 02, 2025 7:13 pm

Relative pathways

Postby JC198998 » Tue Jan 28, 2025 11:54 pm

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: Relative pathways

Postby EViews Gareth » Wed Jan 29, 2025 8:38 am


JC198998
Posts: 13
Joined: Thu Jan 02, 2025 7:13 pm

Re: Relative pathways

Postby JC198998 » Thu Jan 30, 2025 9:24 am

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: Relative pathways

Postby EViews Gareth » Thu Jan 30, 2025 10:03 am

How are primary and secondary related? How are they interacting with each other?

JC198998
Posts: 13
Joined: Thu Jan 02, 2025 7:13 pm

Re: Relative pathways

Postby JC198998 » Thu Jan 30, 2025 9:11 pm

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

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: Relative pathways

Postby EViews Gareth » Fri Jan 31, 2025 9:35 am

Since you are using an include statement, the secondary program will have access to your %main_directory variable.

JC198998
Posts: 13
Joined: Thu Jan 02, 2025 7:13 pm

Re: Relative pathways

Postby JC198998 » Sat Feb 08, 2025 10:31 am

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?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: Relative pathways

Postby EViews Gareth » Sat Feb 08, 2025 12:07 pm

Ah, sorry, yes, forgot. You can’t use string variables with an include.


Return to “General Information and Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 2 guests