Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Load * From CSV (1st Time When CSV doesn't exist)

Hello!

I have a STG where it loads all the fields from CSV files that are continuously being generated over time.

TMP_TABLE: // I force the table to have this fields

  LOAD * INLINE [

      ACCOUNT_ID, DATE

  ];

CONCATENATE

  LOAD *

  FROM ..\Obs_*.csv (txt, utf8, embedded labels, delimiter is ',', msq);

The thing is that the first time that I run this load, I get an error because there aren't any generated files and it can't load anything...

Do you know if there's any way to omit if there aren't any loaded CSV files yet without showing an error, so that it would show a blank file only with the headers and no data at the first time?

Thank you!

1 Solution

Accepted Solutions
ali_hijazi
Partner - Master II
Partner - Master II

if not isnull(filesize('path_to_your_file')) then

load...

endif

I can walk on water when it freezes

View solution in original post

4 Replies
ali_hijazi
Partner - Master II
Partner - Master II

if not isnull(filesize('path_to_your_file')) then

load...

endif

I can walk on water when it freezes
Not applicable
Author

Thank you very much! It worked!

hic
Former Employee
Former Employee

An alternative, more elegant way, would be the following:

Set vConcatenatePrefix = ;

For each vFileName in FileList('C:\Path\*.csv')

     $(vConcatenatePrefix)

     Load * From [$(vFileName)] (...) ;

     Set vConcatenatePrefix = Concatenate;

Next vFileName

FileList returns a list of files. If there are no files, the loop is never entered. The first loop, the vConcatenatePrefix will expand to an empty string. The second loop, it will expand to 'Concatenate'.

HIC

Not applicable
Author

Thank you Henric! I'm going to try it and tell you the results!