Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
ehann2343
Contributor II
Contributor II

How to get a filename as a variable to check against If Else conditions?

I need to load different sets of column names from excel sheet files based on the file name's month/year which is labeled name month year (example: FILEJAN22). The basic set up I have right now is for each file, check if the year is <= 22, if so load these 5 column names, and if not if its 23 AND the month is August through December, then load this other set of 5 column names. 

Having trouble figuring out how to get the current file that the loop is using to pull out the month and year of that file in order for it to be checked properly. Any solutions or advice is appreciated.  

 
Labels (2)
5 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

How are you looping? With Filelist() or wildcard?

-Rob

Aditya_Chitale
Specialist
Specialist

You can use filename() function inside your table script in combination with functions like left() & right() to extract desired part from file name string.

Regards,

Aditya

ehann2343
Contributor II
Contributor II
Author

I am not using either, I am just using a for each dir in dirlist (*) and then for each file in filelist(*);
Would I be able to pull a file name each time in my for loop with Filelist()? What would be some foundational code for that?

ehann2343
Contributor II
Contributor II
Author

Do you have some example filename() function code I could refer to?

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

For each fname in FileList('*.xlsx')

  if mid('$(fname)', 10, 2) = '22' Then ...

Next