<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problem with &amp;quot;for each&amp;quot; loop in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Problem-with-quot-for-each-quot-loop/m-p/313656#M1198070</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;This is an extract of my VB 6 code. This should work for you:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;&lt;BR /&gt; Sub ProcessReports(TargetPath As String)&lt;BR /&gt; Dim objFSO' AsScripting.FileSystemObject&lt;BR /&gt; Dim objParFolder' As Folder&lt;BR /&gt; Dim objFolder' As Folder&lt;BR /&gt; Dim objFile' As File&lt;BR /&gt; Set objFSO =CreateObject("Scripting.FileSystemObject")&lt;BR /&gt; Set objParFolder =objFSO.GetFolder(TargetPath)&lt;BR /&gt; For Each objFileIn objParFolder.Files&lt;BR /&gt; If UCase(Right(objFile.Name, 3)) = "XLS" Then&lt;BR /&gt; 'File name is objFile.Name&lt;BR /&gt; 'Load statement here&lt;BR /&gt; End If&lt;BR /&gt; Next&lt;BR /&gt; 'Process subfolders&lt;BR /&gt; For Each objFolder InobjParFolder.SubFolders&lt;BR /&gt; ProcessFilesInSubFolderobjFolder&lt;BR /&gt; Next&lt;BR /&gt; Set objFile = Nothing&lt;BR /&gt; Set objFolder = Nothing&lt;BR /&gt; Set objParFolder = Nothing&lt;BR /&gt; Set objFSO = Nothing&lt;BR /&gt;End Sub&lt;BR /&gt;Sub ProcessFilesInSubFolder(SubFolder As Folder)&lt;BR /&gt;Dim objFile' As File&lt;BR /&gt;Dim objFolder' As Folder&lt;BR /&gt;For Each objFile In SubFolder.Files&lt;BR /&gt; If UCase(Right(objFile.Name, 3))= "XLS" Then&lt;BR /&gt; 'File name is objFile.Name&lt;BR /&gt; 'Load statement here&lt;BR /&gt; End If&lt;BR /&gt;Next&lt;BR /&gt;Set objFile = Nothing&lt;BR /&gt;For Each objFolder In SubFolder.SubFolders&lt;BR /&gt; ProcessFilesInSubFolder objFolder&lt;BR /&gt;Next&lt;BR /&gt;Set objFolder = Nothing&lt;BR /&gt;End Sub&lt;BR /&gt;Sub cmdProcess_Click()&lt;BR /&gt; ProcessReports vRootPath&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 16 Mar 2011 06:07:12 GMT</pubDate>
    <dc:creator>vupen</dc:creator>
    <dc:date>2011-03-16T06:07:12Z</dc:date>
    <item>
      <title>Problem with "for each" loop</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-quot-for-each-quot-loop/m-p/313655#M1198069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have run into a problem with my "for each" loop. I found most of my code here.&lt;BR /&gt;I am looping through directories and loading any excel files that i find.&lt;BR /&gt;The problem is that I start my load one level too deep.&lt;/P&gt;&lt;P&gt;Folder structure:&lt;/P&gt;&lt;P&gt;App (qvw)&lt;BR /&gt;+Folder 1&lt;BR /&gt; +A&lt;BR /&gt; +1A&lt;BR /&gt; +1B&lt;BR /&gt; +B&lt;BR /&gt; +C&lt;BR /&gt;+Folder 2&lt;BR /&gt; +D&lt;BR /&gt; +E&lt;BR /&gt; +F&lt;/P&gt;&lt;P&gt;Now I start loading files in folder A .... then B...therefore I miss any excel files that might be directly under "Folder 1", not in subfolder.&lt;BR /&gt;I don't want to load the files in Folder 2.&lt;/P&gt;&lt;P&gt;&lt;B&gt;CODE:&lt;/B&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;for each vDirectory in dirlist (vRoot&amp;amp;'\*')&lt;/P&gt;&lt;P&gt;LET vFolderName = subfield('$(vDirectory)', '', -1);&lt;/P&gt;&lt;P&gt;for each vFile in filelist (vDirectory&amp;amp;'\*.xls')&lt;/P&gt;&lt;P&gt;List:&lt;/P&gt;&lt;P&gt;LOAD *,&lt;/P&gt;&lt;P&gt;'$(vFolderName)' as Folder,&lt;/P&gt;&lt;P&gt;FileDir('$(vDirectory)') as Path,&lt;/P&gt;&lt;P&gt;FileName('$(vFile)') as File&lt;/P&gt;&lt;P&gt;FROM [$(vFile)] (biff, embedded labels, header is 1 lines, table is Blad1$);&lt;/P&gt;&lt;P&gt;next vFile&lt;/P&gt;&lt;P&gt;next vDirectory&lt;/P&gt; &lt;B&gt;&lt;/B&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;DIV&gt;Thanks for any help&lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Mar 2011 23:23:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-quot-for-each-quot-loop/m-p/313655#M1198069</guid>
      <dc:creator>qw_johan</dc:creator>
      <dc:date>2011-03-15T23:23:01Z</dc:date>
    </item>
    <item>
      <title>Problem with "for each" loop</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-quot-for-each-quot-loop/m-p/313656#M1198070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;This is an extract of my VB 6 code. This should work for you:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE style="overflow-x: scroll;"&gt;&lt;PRE style="margin: 0px;"&gt;&lt;BR /&gt;&lt;BR /&gt; Sub ProcessReports(TargetPath As String)&lt;BR /&gt; Dim objFSO' AsScripting.FileSystemObject&lt;BR /&gt; Dim objParFolder' As Folder&lt;BR /&gt; Dim objFolder' As Folder&lt;BR /&gt; Dim objFile' As File&lt;BR /&gt; Set objFSO =CreateObject("Scripting.FileSystemObject")&lt;BR /&gt; Set objParFolder =objFSO.GetFolder(TargetPath)&lt;BR /&gt; For Each objFileIn objParFolder.Files&lt;BR /&gt; If UCase(Right(objFile.Name, 3)) = "XLS" Then&lt;BR /&gt; 'File name is objFile.Name&lt;BR /&gt; 'Load statement here&lt;BR /&gt; End If&lt;BR /&gt; Next&lt;BR /&gt; 'Process subfolders&lt;BR /&gt; For Each objFolder InobjParFolder.SubFolders&lt;BR /&gt; ProcessFilesInSubFolderobjFolder&lt;BR /&gt; Next&lt;BR /&gt; Set objFile = Nothing&lt;BR /&gt; Set objFolder = Nothing&lt;BR /&gt; Set objParFolder = Nothing&lt;BR /&gt; Set objFSO = Nothing&lt;BR /&gt;End Sub&lt;BR /&gt;Sub ProcessFilesInSubFolder(SubFolder As Folder)&lt;BR /&gt;Dim objFile' As File&lt;BR /&gt;Dim objFolder' As Folder&lt;BR /&gt;For Each objFile In SubFolder.Files&lt;BR /&gt; If UCase(Right(objFile.Name, 3))= "XLS" Then&lt;BR /&gt; 'File name is objFile.Name&lt;BR /&gt; 'Load statement here&lt;BR /&gt; End If&lt;BR /&gt;Next&lt;BR /&gt;Set objFile = Nothing&lt;BR /&gt;For Each objFolder In SubFolder.SubFolders&lt;BR /&gt; ProcessFilesInSubFolder objFolder&lt;BR /&gt;Next&lt;BR /&gt;Set objFolder = Nothing&lt;BR /&gt;End Sub&lt;BR /&gt;Sub cmdProcess_Click()&lt;BR /&gt; ProcessReports vRootPath&lt;BR /&gt;End Sub&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Mar 2011 06:07:12 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-quot-for-each-quot-loop/m-p/313656#M1198070</guid>
      <dc:creator>vupen</dc:creator>
      <dc:date>2011-03-16T06:07:12Z</dc:date>
    </item>
    <item>
      <title>Problem with "for each" loop</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-quot-for-each-quot-loop/m-p/313657#M1198071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Mulumudi,&lt;/P&gt;&lt;P&gt;Thanks for your reply.&lt;BR /&gt;But I feel like my code is better, at least more compact with just ~10 lines of code.&lt;BR /&gt;And it works to 99%...&lt;/P&gt;&lt;P&gt;The problem is that my code doesn't scan for excel files at first loop. vRoot holds full path to app directory.&lt;BR /&gt;I also tried :&lt;BR /&gt;for each vDirectory in dirlist (&lt;B&gt;&lt;I&gt;if(vFlag, vRoot&amp;amp;'\*', vRoot)&lt;/I&gt;&lt;/B&gt;)&lt;/P&gt;&lt;P&gt;Using vRoot i get want at top level, using vRoot&amp;amp;'\*' i get all directories...i need to combine these two options.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Mar 2011 13:21:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-quot-for-each-quot-loop/m-p/313657#M1198071</guid>
      <dc:creator>qw_johan</dc:creator>
      <dc:date>2011-03-16T13:21:44Z</dc:date>
    </item>
    <item>
      <title>Problem with "for each" loop</title>
      <link>https://community.qlik.com/t5/QlikView/Problem-with-quot-for-each-quot-loop/m-p/313658#M1198072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I found a solution in the helpfile.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sub DoDir (Root)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for each Ext in 'xls' //'qvw', 'qvo', 'qvs', 'qvt', 'qvd'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for each File in filelist (Root&amp;amp;'\*.' &amp;amp;Ext)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Load '$(File)' as Namn, FileSize( '$(File)' ) as Size, FileTime( '$(Fil)' ) as Filtid&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;autogenerate 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;next File&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;next Ext&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for each Dir in dirlist (Root&amp;amp;'\*' )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;call DoDir (Dir)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;next Dir&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;end sub&lt;/P&gt;&lt;P&gt;&lt;/P&gt;call DoDir ('C:\') &lt;BR /&gt;&lt;BR /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Mar 2011 19:02:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Problem-with-quot-for-each-quot-loop/m-p/313658#M1198072</guid>
      <dc:creator>qw_johan</dc:creator>
      <dc:date>2011-03-16T19:02:18Z</dc:date>
    </item>
  </channel>
</rss>

