Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Load latest file - filetype can be either .txt or .csv

Hi all,

I have a script which will load the latest file in a stated folder.   Currently it is the latest .CSV but sometimes a .txt file is saved.....

I need help on what changes is required in my load script, to now take into account the .txt files.  So basically I require to load the latest file, no matter what file extension it has.

This is my current code:


If FileSize('F:\file_location\*.csv')>0 then
for each File in filelist ('F:\file_location\*.csv')
Folder:
Load '$(File)' as Name,
FileTime( '$(File)' ) as FileTime
autogenerate 1;
next File

LatestFile:
first 1
Load
Name,
FileTime,
1
as dummy
Resident Folder
Order By FileTime DESC;
drop table Folder;

LOAD [@1:n] as 'Image Data'
FROM
'$(File)'
(
fix, utf8, no labels);
ELSE 

Temp:
Load MsgBox ('No files found in the folder!','Status','OKCANCEL','ICONHAND') AutoGenerate 1;
DROP Table Temp;
ENDIF

7 Replies
oknotsen
Honored Contributor III

Re: Load latest file - filetype can be either .txt or .csv

Replace the extention (.csv or .txt) by a star. That should do the trick.

I suggest you avoid putting other files in that folder else it might get messy.

May you live in interesting times!
Not applicable

Re: Load latest file - filetype can be either .txt or .csv

‌that was the 1st thing I tried but it didn't work

oknotsen
Honored Contributor III

Re: Load latest file - filetype can be either .txt or .csv

Did you replace it in both locations?

Let me put it this way:

On a frequent basis I have been loading multiple files from a folder that matches "emp*.*" and it worked every time. Maybe "*.*" is not allowed, but that somehow sounds very strange.

May you live in interesting times!
Not applicable

Re: Load latest file - filetype can be either .txt or .csv

‌I did replace in both locations.

I'm starting to think the script to load the most recent file is not working - can you / anyone spot a mistake In the code?

thanks

oknotsen
Honored Contributor III

Re: Load latest file - filetype can be either .txt or .csv

So are you saying the initial script does not work in the current situation under the current requirements?

I was replying under the assumption that the initial script worked and you only were looking for a way to change it to meet changed requirements.

May you live in interesting times!
Not applicable

Re: Load latest file - filetype can be either .txt or .csv

I got it to work by moving all the exiting files to an archive folder.  So the folder will always contain only the latest file.

Thanks for your help

oknotsen
Honored Contributor III

Re: Load latest file - filetype can be either .txt or .csv

Happy you figured it out yourself .

May you live in interesting times!
Community Browser