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: 
Not applicable

Find Max Date Change in a list of files in a folder

Is there a way to get the Max Date Modified in a folder.  I have the following folder location:

C:\Users\dyoung\Documents\Qlik\Sense\Apps\F_Gates\backups\

In that folder I have a bunch of back files that look like this:

Name                                                                      Date Modified

backup_F_Gates_160214_0006.dist                          2/14/2016

backup_F_Gates_160212_0008.dist                          5/15/2016

backup_F_Gates_160233_0010.dist                          4/20/2016

backup_F_Gates_160244_0011.dist                          3/13/2016

I would want to only return:

backup_F_Gates_160212_0008.dist                          5/15/2016


Is this possible?  I have posted this in other places and tried it in other discussion groups but I could not get it to work. 


Here is the code I used.  I created a folder connection to Backups.

set vPath = 'Backups';

for each File in filelist ('Backups\backup_F_Gates_*.dist')

fileTable:

Load '$(File)' as Name,

  num(FileTime('$(File)')) as FileTime

  autogenerate 1;

next File

Modified_Time:

Load max(Filetime) as ModifiedTime

Resident fileTable;

let vMaxTime = num(peek('ModifiedTime',0,'Modified_Time'));

if len(TableNumber('fileTable')) >= 1 then

FinalTMP:

LOAd

SubField(Name,'\',-1)as File,

rowno() as Recno

RESIDENT fileTable

WHERE FileTime > '$(vMaxTime)'+0.001

ORDER BY FileTime desc;

Drop table fileTable;

Let VMxRows = NoOfRows('FinalTMP');

if  $(VMxRows) >0 then

for i=0 to $(VMxRows)-1

let FileRead = peek('File',$(i),'FinalTMP');

Data:

Load *,

FileName() as Filename,

FileTime() as FileTime

From $(vPath)\$(FileRead);

I tried to code but it is not working.  There is a way I am sure to get it.  Any help would be awesome. 


Thanks,

David

2 Replies
swuehl
MVP
MVP

Could you explain what you want to achieve with

FinalTMP:

LOAd

SubField(Name,'\',-1)as File,

rowno() as Recno

RESIDENT fileTable

WHERE FileTime > '$(vMaxTime)'+0.001;

?

And with the code that follows that table?

I would have thought that a table load like

Modified_Time:

Load

     Timestamp(max(Filetime)) as ModifiedTime,

     FirstSortedValue(Name, -Filetime) as LastModifiedFileName

Resident fileTable;

should return your requested record.

Not applicable
Author

‌That was code that someone had me try so I am not sure what it does.  My goal is to get the latest or max date modified in a folder.  If you look at the response above I have a folder called Backups.

each file in the folder has file with *backup and a date modified.

So the folder has 30 backup files and I want the file with the latest edition modified date. 

Example of folder

*.backup01  Modified date 2/3/2016

*.backup02  Modifed date 5/16/1016

*.backup03  Modifed date 4/3/2016

*.backup04  Modifed date 3/16/2016

I want the response to return me *.backup02 only since it was the max modified date.  I hope this makes since. 

Thanks

David