Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
jmialoundama
Specialist
Specialist

Load only last CSV file of floder

Hello, 

 

I have multiple CSV file in my folder. The name of CSV file is like that : 

 

20181125 -product-extract

20180820-product-extract

20180910-product-extract

I have a script and i want to load only last CSV file, but i would like to know how can i do this ? 

Thanks in advance 🙂 

1 Solution

Accepted Solutions
jmialoundama
Specialist
Specialist
Author

Hello,

I solded my problem. I update script like this and it's works : 

LET vFilePath ='lib://AttachedFiles';
FOR EACH file in FileList('$(vFilePath)/*.csv'); // Loops each excel file in the given Folder
LET vFileDate = Date(Left(right(file,28),8)); // Gets the year portion from the filename
LET vMaxDate = Rangemax(vFileDate, vMaxDate); // Gets the max year for every iteration
NEXT


Data:
LOAD *
FROM [$(vFilePath)/$(vMaxDate)-product-extract.csv]
(txt, utf8, embedded labels, delimiter is '|', msq);

With this script i get the latest csv file.

 

Thanks your for your help 🙂 

View solution in original post

7 Replies
Thiago_Justen_

Here it is:

 

For each vFile in FileList('lib://YOUR_PATH/*.csv')

LET vFileName = SubField('$(vFile)','/',-1);

LET vDate = Date(Date#(Left('$(vFileName)',8),'YYYYMMDD'),'YYYYMMDD');

tmpFiles:

LOAD '$(vFile)' as File, '$(vFileName)' as FileName, '$(vDate)' as Date AutoGenerate 1;

next

Files:

LOAD Max(Date) as Date RESIDENT tmpFiles;

LEFT JOIN (Files)

LOAD File, Date RESIDENT tmpFiles;

DROP TABLE tmpFiles;

For i = 0 to NoOfRows('Files') -1

LET vSourceFile = peek('File',$(i),'Files');

data:

LOAD * FROM [$(vSourceFile)] (csv);

Next

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
jmialoundama
Specialist
Specialist
Author

Hello Thiago, 

 

Thanks you for your aswer.

 

I try this script ,but it's not works and i didn't see where error can provide : 

 

 I  have multiple csv file like this : 

20181120-product-extract.csv

20180805-product-extract.csv

20180901-product-extract.csv

I want to load only last csv file. 

I try to applicate this script to load lastest CSV file , but it's not working and i can't to see my error. 

 

I update the script like this  : 

LET vFilePath = 'lib://AttachedFiles/*-product-extract.csv';
FOR EACH file in FileList('$(vFilePath)'); // Loops each excel file in the given Folder
LET vFileDate = Date((Left(file,8)); // Gets the year portion from the filename
LET vMaxDate = Rangemax(vFileDate, vMaxDate); // Gets the max year for every iteration
NEXT


Data:
LOAD sku
FROM [lib://AttachedFiles/$(vMaxDate)-product-extract.csv]
(txt, utf8, embedded labels, delimiter is '|', msq);

 

Error : "Cannot open file 'lib://AttachedFiles/-product-extract.csv' 

jmialoundama
Specialist
Specialist
Author

Thiago, 

 

I try your script and i have same error : Cannot open file: 'lib://AttachedFiles/lib://AttachedFiles/20181118-product-extract.csv-product-extract.csv'

Thiago_Justen_

Change this piece of code:

From:

LET vFilePath = 'lib://AttachedFiles/*-product-extract.csv'; 

 

To:

LET vFilePath = 'lib://AttachedFiles/*.csv';

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago
jmialoundama
Specialist
Specialist
Author

Hello,

I solded my problem. I update script like this and it's works : 

LET vFilePath ='lib://AttachedFiles';
FOR EACH file in FileList('$(vFilePath)/*.csv'); // Loops each excel file in the given Folder
LET vFileDate = Date(Left(right(file,28),8)); // Gets the year portion from the filename
LET vMaxDate = Rangemax(vFileDate, vMaxDate); // Gets the max year for every iteration
NEXT


Data:
LOAD *
FROM [$(vFilePath)/$(vMaxDate)-product-extract.csv]
(txt, utf8, embedded labels, delimiter is '|', msq);

With this script i get the latest csv file.

 

Thanks your for your help 🙂 

Thiago_Justen_

Sound good. If my responses were useful, please give like to those.

 

Cheers

Thiago Justen Teixeira Gonçalves
Farol BI
WhatsApp: 24 98152-1675
Skype: justen.thiago