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

How to check file if exists and if not then create a file

Hi want to record metadata of QVD load into a QVD file. For this every QVD builder app should run this script first.

If File exists, then do nothing. Else create the file.

 

I am using following code, but every time it overwrites with blank data.

Set vFilePath = 'C:\QVD_Files\Metadata.QVD' ;


	IF FileSize($(vFilePath)) > 0 THEN  // Do Nothing
   
        ELSE  // Create the following QVD

	MetaData:
            
   	LOAD * INLINE 
                
   		[
     		TableName, RowCount, FieldCount, LoadDateStamp
         ];
                    
               	STORE 	MetaData into $(vFilePath )(qvd);
                 
            DROP TABLE 	MetaData;
            
         END IF  
         

 

Am I writing the if statement incorrectly? If so, then what would be the best way to write it. Thank you

 

Labels (2)
1 Solution

Accepted Solutions
Vegar
MVP
MVP

A tiny adjustment will solve your issue. Change marked in blue,


IF FileSize('$(vFilePath)') > 0 THEN
   Trace Do Nothing;
ELSE 
  Trace Create the following QVD;
  MetaData:
  LOAD * INLINE
  [
  TableName, RowCount, FieldCount, LoadDateStamp
  ];
  STORE MetaData into $(vFilePath)(qvd);
  DROP TABLE MetaData;
END IF

View solution in original post

2 Replies
Vegar
MVP
MVP

A tiny adjustment will solve your issue. Change marked in blue,


IF FileSize('$(vFilePath)') > 0 THEN
   Trace Do Nothing;
ELSE 
  Trace Create the following QVD;
  MetaData:
  LOAD * INLINE
  [
  TableName, RowCount, FieldCount, LoadDateStamp
  ];
  STORE MetaData into $(vFilePath)(qvd);
  DROP TABLE MetaData;
END IF

qs123
Contributor II
Contributor II
Author

Thanks Vegar 🙂 power of code review 😁