Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
shansundar
Partner - Creator
Partner - Creator

How to filter inside a for loop in subroutine

Hi Qlikers,

I need to filter a particular named txt files from the root folder (including all sub folders in it). I'm using the following sub routine and then filtering the sub routine result set to achieve the desired result.

sub ScanFolder(Root)

  for each FileExtension in 'txt'

  for each FoundFile in filelist( Root & '\*.' & FileExtension)

  FileList:

  LOAD '$(FoundFile)' as SourceFile,

  FileTime( '$(FoundFile)' ) as Filetime

  AUTOGENERATE 1;

  Set vConcatenate = Concatenate;

  next FoundFile

  next FileExtension

  for each SubDirectory in dirlist( Root & '\*' )

  call ScanFolder(SubDirectory)

  next SubDirectory

end sub;


Call ScanFolder ('myfolder\Log');


FinalFileList:

NOCONCATENATE

LOAD

SourceFile,

Filetime

RESIDENT FileList

WHERE SourceFile LIKE '*Reload_Task_Check';

My question is it is possible to filter the name of the txt file inside the subroutine itself? Can you please help me here.

Thanks,

Shan S

1 Solution

Accepted Solutions
marcus_sommer

Try this:

...

  for each FoundFile in filelist( Root & '\*.' & FileExtension)

     if '$(FoundFile)' = 'xxx' then

          ...

     else

          ...

     end if

  next

...

- Marcus

View solution in original post

3 Replies
marcus_sommer

Try this:

...

  for each FoundFile in filelist( Root & '\*.' & FileExtension)

     if '$(FoundFile)' = 'xxx' then

          ...

     else

          ...

     end if

  next

...

- Marcus

Peter_Cammaert
Partner - Champion III
Partner - Champion III

or add the known part of the file name to look for to the wildcard specification in your inner for loop. Like

for each FoundFile in filelist( Root & '\*Reload_Task_Check.' & FileExtension)

:

shansundar
Partner - Creator
Partner - Creator
Author

I have included IF condition and it works fine.

Thanks,

Shan S