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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
mwscott1
Creator
Creator

Load text file in folder with most recent Date Modified

Each day a new file is added to the folder C:\Users\Daily Feed\. The filename is always the same except for the highlighted section in the script below. The highlighted section is the date MMDDYYY with a series of numbers after. The numbers after the date are always different. So each day I have to update my script with the new filename.  Is there a way to read only the most recent file in the folder based on the date in the file name or possible the Modified Date of the file?

LOAD @1,
@2,
@3 as [USER ID],
@4,
@5
FROM
[C:\Users\Daily Feed\Datafeed User and OU Feed results - 03_31_2021_07_07_10-Errors.txt]
(txt, codepage is 1252, no labels, delimiter is spaces, msq, header is 76 lines)where (@4)='UserName';

Labels (1)
1 Reply
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Load a table of files using either Filelist() or Load * and then filter the list using some criteria like FileTime. Put the winner in a variable and use the variable as your file path in the Load. For example:

TempFiles:
First 1
LOAD
  FilePath() as FilePath,
  FileTime() as FileTime
From [*.txt] (fix, utf8, no labels)
;
TempLatest:
Load
  FirstSortedValue(DISTINCT FilePath, -FileTime) as LatestFile
Resident TempFiles
;
LET vLatestFile = peek('LatestFile');
DROP Tables TempFiles, TempLatest; 

LOAD ... FROM [$(vLatestFile)] ...

-Rob
http://masterssummit.com
http://qlikviewcookbook.com
http://www.easyqlik.com