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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
kdmarkee
Specialist
Specialist

Use dynamic name in subdirectory looping

I want to loop through subdirectories and load the file names ONLY for files with certain text in the file name, where that text is variable from month to month...for example April's files will have "201904" in the name, May's files will have "201905" in the file name.  I have the looping working but cannot seem to figure out how to filter out unwanted filenames and dynamically select the files I do want using my variable $(vMEDate).  Here is my code thus far; can someone offer suggestions on how to accomplish my goal?  Thanks.

let vMERootDir = '\\MYFOLDER\MEReports\TEST\';
let vMEDate = Year(MonthStart(Today())-1) & Num(Month(MonthStart(Today())-1), '00'); //look for latest files only, ie 201904

sub DoDir (Root)
for each Ext in 'pdf'

for each File in filelist (Root & '\*.' & Ext)
ReportOutput_temp:
LOAD
FileBaseName() as PDFReportFileName
from $(File)
;
next File

next Ext

for each Dir in dirlist (Root & '\*' )
call DoDir (Dir)
next Dir

end sub

call DoDir ('$(vMERootDir)')

Labels (1)
1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think you can just modify your forfiles to include the variable:

for each File in filelist (Root & '\*$(vMEDate)*.' & Ext)

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

View solution in original post

2 Replies
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

I think you can just modify your forfiles to include the variable:

for each File in filelist (Root & '\*$(vMEDate)*.' & Ext)

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

kdmarkee
Specialist
Specialist
Author

Thanks, I had tried that but I must have had my syntax wrong.