Discussion Board for collaboration on QlikView Scripting.
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
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.
that was the 1st thing I tried but it didn't work
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.
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?
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.
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
Happy you figured it out yourself .