Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
I wrote this code to load different sales files by month:
FOR i = 1 to 12
// Generate file name based on month
LET vMonth = Pick(i,
'january', 'february', 'march', 'april', 'may', 'june',
'july', 'august', 'september', 'october', 'november', 'december'
);
trace $(i);
trace $(vMonth);
// File path
LET vFile = 'lib://MyData/sales_' & vMonth & '.csv';
trace $(vFile);
// Load data from file
Sales:
LOAD
Date,
Product,
Amount,
Price
FROM [$(vFile)]
(txt, utf8, embedded labels, delimiter is ';', msq);
NEXT i
If I only have 2 files (e.g "sales_january.csv" and "sales_february.csv") in MyData directory, I get a "Cannot open file 'lib://MyData/sales_march.csv' error.
How can I load only existing files without getting this error?
Thanks in advance for your help,
Jose
Check if File exists
IF FileSize($(vFile)) > 0 Then
Sales:
Load *
From [$(vFile)]
End IF