Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
parvez933
Creator
Creator

path into variable

Hi Everyone!

All my project related files/qvd's/qvs/etc are stored in D:\Data1\<file names>

So, I am using an variable as

SET v1= '.\'

But, what if the file is located in the C:\<file name> how write the path to store into an variable.

If I am using SET v2='\' it is searching in the 'D:\' and throwing an error as 'File not found D:\Data1\<File Name>' 

Can any one help in understanding the same and what is the difference between

SET v1='..\' and SET v1='.\'

1 Solution

Accepted Solutions
avkeep01
Partner - Specialist
Partner - Specialist

Because the .QVW is saved on the D-drive. 

..\ is a relative path. the relative path is based on the location of the .QVW.

View solution in original post

10 Replies
Somasundaram
Creator III
Creator III

Hi,

if you want to add drive as well you can keep a separate file contains all the variable with full path.

include the file and use it. if you want to change the drive just change the filename  which is contains correct paths

Hope it might useful


-Somasundaram

If this resolves your Query please like and accept this as an answer.
parvez933
Creator
Creator
Author

Hey Somasundaram,

Thank you for your response! I understand your process of storing the variables into a file and including the same.

But, I want to know if there are 2 file file1 from D drive and file2 from E drive. How can I store them in a variable by using the SET.

Yes! I am aware we can do this by the include file. But can you help be how to define in the SET.

Set v1='D:\Data1\<>' to ????

SET v2='E:\<>' or 'E:\Data\<>' to ????

Is this even possible or else I have to include the variables from the include file!!!
Somasundaram
Creator III
Creator III

SET v1 ='D:\Data1\
SET v2 ='E:\Data1\'

you can create the variables and include the file. while changing the drive just change the variable.
ex. if you want to point to D:.use $(V1)\
for E: $(V2)\



-Somasundaram

If this resolves your Query please like and accept this as an answer.
avkeep01
Partner - Specialist
Partner - Specialist

Hi @parvez933

 

You can use SET and LET to define a variable. With SET you just basically enter the text, while with the help op LET you can make it dynamic. 

As far as I understood I think there are two solutions 

1. use an IF statement in the script. 

Table: LOAD * FROM Datasource; 

IF $(v1) <> TO '????' THEN 

STORE Table into $(v2) ;

ELSE 

STORE Table into $(v1); 

END IF 

 

2. Make the variable dynamic. 

LET v3 = IF('D:\Data\'<> '????','E:\Data\','D:\Data\'; 

 

STORE Table into $(v3); 

 

avkeep01
Partner - Specialist
Partner - Specialist

Hi @parvez933

You could check the error message, en when it exists then you pull the data from v2. 

SET ErrorMode = 0;

LOAD * FROM $(v1);

// Check the error message
Errors:
LOAD
'$(ScriptError)' AS Error
AutoGenerate (1);

IF LEN(PEEK('Error',-1,'Errors'))>0 THEN

// In case of error:
LOAD * FROM $(v2);

END IF

parvez933
Creator
Creator
Author

Hey Thank You for the response!

But I am looking for something else.

Can I know! How can we read the data from 2 different files which are stored in different Drives , and how to store the path into an variable.

Ex:

File1---> D:\Data\Datasource\File1

Since, my project is store in the same folder of D drive. I will store the path into a variable as

SET v1='..\' or SET v1='.\'

and I will use load * from $(v1)File1 

It is working good as the project and file is located in the same folder of Data source.

The File2--->  D:\Else\Doing\File2

For which I used SET v2= '..\'

It is also working. Here the main thing is I want the Drive Names [D:\ or E:\] should be removed

In the same way! how can I store the file path which is stored in E drive without using the Drive name

Ex:

File3----> E:\Dumb\nosense\File3

How to write it to avoid using the DRIVE name

Set v3='.\' or '..\' or '\Dumb\Nonsense\'

parvez933
Creator
Creator
Author

1.png

avkeep01
Partner - Specialist
Partner - Specialist

Because the .QVW is saved on the D-drive. 

..\ is a relative path. the relative path is based on the location of the .QVW.

parvez933
Creator
Creator
Author

Hey AV,
Thank you! For your response! I was not sure that path will depend on .qvw file.
It helps!
So can I make a statement that since qvw is in D drive, I can use ..\ in the variable and for E drive I have to create a new variable with absolute path.
Ex:
Qvw is in D drive. I can write as
Set v1= '..\';
To use E drive files I have to use complete path by storing in an excel r notepad.
Set v2= 'E:\file'; and no shortcuts to use E drive files as (..\ or \)