Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

HOw to write for loop in script side

Hi,

I want to write for loop in script side so how to write in qvw file.

Administrator

3 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

     The syntax is same.

     For i=0 to 10

         

          .........

     Next

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
MayilVahanan

HI

This is one of the example for retrieve all files in folder by using for loop in script

Sub loadfiles(Files)

  For Each file in FileList('$(Files)' & '\*.*');

  TestLoad:

  LOAD '$(file)' AS FilePath,

  if(Len(SubField('$(file)','.',-1)) < 8,SubField('$(file)','.',-1),'No Extension') AS FileExtension,

  FileSize('$(file)') AS FileSize,SubField('$(file)','\',SubStringCount('$(file)','\')+1) As FileName,

  FileTime('$(file)') AS FileTime AutoGenerate 1;

  NEXT file;

  For Each subdir in DirList('$(Files)' & '\*');

  CALL subFunction('$(subdir)')

  NEXT subdir;

End Sub

SUB subFunction(Subdir)

  For Each sub in DirList('$(Subdir)')

  CALL loadfiles('$(sub)')

  NEXT sub;

End Sub

Call loadfiles('E:\Qlikview -11')

Drop Tables "*";

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.
hic
Former Employee
Former Employee

There are many ways to do this. For an overview, see Loops in the Script.

HIC