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

Load last file

Dear All,

I made incremental module, It's working fine for those files where I'm using static file name.

Now new requirement is that, I would like to load last created file in a folder.

For example:

First time, I loaded data from data source "SaleData-Mar01.csv".

Next time to onward, just I have to paste a file in a data source folder such as "SaleData-Mar02.csv", and load script should automatically consider it where from data should be load.

Days after days, data source files will be increased, means:

First day folder consist on: "SaleData-Mar01.csv"

Second day folder consist on: "SaleData-Mar02.csv"

Third day folder consist on: "SaleData-Mar03.csv"

and so on...

Please note, file name can be different for new day.

Kind regards,

Ishfaque Ahmed

3 Replies
Not applicable

Hi ,

You can find very helpful script in QV help. I think this is exactly what you need. Based on this script you can easy identify last created file by name or by timestamp. See operator for each..next.

FOR Each File in filelist (Root&' \*.' &Ext)

LOAD

'$(File)' as Name,

FileSize( '$(File)' ) as Size,

FileTime( '$(File)' ) as FileTime

autogenerate 1;

NEXT File

engishfaque
Specialist III
Specialist III
Author

Dear All,

Any one can share me best solution for loading last data source file?

Kind regards,

Ishfaque Ahmed

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Taras already did.

You only need to add code to lift the most recent file from the newly created table, like in:

// Taras' FOR-EACH solution comes here. Call the table [RawFileNames]

OrderedFileNames:

LOAD Name, FileTime

RESIDENT RawFileNames

ORDER BY FileTime DESC;

DROP Table RawFileNames;

LET vNewestFilePath = peek('Name', 0, 'OrderedFileNames')

DROP Table OrderedFileNames;

// Variable vNewestFilePath now contains the name of the most recent file

// in folder 'Root' with extension 'Ext'

Best,

Peter