FileSystemObject - Horizontal Loop

Hello Gemtlemen,
I have the attached code, which uses the FSO to list image files in a particular folder on the server. It runs through the folder and outputs the images in a straight list of <div>s on the page.

I would like to modify the code so as to output the images in a 4 column table with the number of rows being determined dynamically by the number of images in the folder.
Essentially what I want is a Horizontal Looper code.

I am able to do this using records pulled from a recordset, but cant find the correct way to do this with the FSO code attached.

Any help much appreciated.


Coddie
<% 
Sub Recurse(Path)
	
	Dim fso, Root, WindowsFolder, Files, Folders, File, i, FoldersArray(100)
		
	Const ForReading = 1
	Set fso = Server.CreateObject("Scripting.FileSystemObject")
	Set Root = fso.getfolder(Path)
	Set Files = Root.Files
	Set Folders = Root.SubFolders
	
	For Each File In Files 
	if file.name <> (rsGalleryDetail.Fields.Item("fldGalleryPic").Value) then
	%>
<div class="thumb"><a href="<%=thepath & file.name%>" title="<%=(rsGalleryDetail.Fields.Item("fldGalleryTitle").Value)%>" rel="lightbox[<%=(rsGalleryDetail.Fields.Item("fldGalleryID").Value)%>]"><img src="<%=thepath & file.name%>" alt="View Full Size" width="<%=(rsGalleryConfig.Fields.Item("fldGalleryThumb").Value)%>" border="0" /></a></div>
	<% end if
	Next
		 	
	For i = 0 To UBound(FoldersArray)
		if FoldersArray(i) <> "" Then 
			Recurse FoldersArray(i)				
		Else
			Exit For
		End if
	Next
	
End Sub
%>

Open in new window

coddieAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi, try this....I've just added a column counter, and written <BR> when it gets to four....

<%
Sub Recurse(Path)
      
      Dim fso, Root, WindowsFolder, Files, Folders, File, i, FoldersArray(100)
            
      Const ForReading = 1
      Set fso = Server.CreateObject("Scripting.FileSystemObject")
      Set Root = fso.getfolder(Path)
      Set Files = Root.Files
      Set Folders = Root.SubFolders
      
      intCol = 0
      For Each File In Files
            if file.name <> (rsGalleryDetail.Fields.Item("fldGalleryPic").Value) Then
                  intCol = intCol + 1
                  %>
                  <td><div class="thumb"><a href="<%=thepath & file.name%>" title="<%=(rsGalleryDetail.Fields.Item("fldGalleryTitle").Value)%>" rel="lightbox[<%=(rsGalleryDetail.Fields.Item("fldGalleryID").Value)%>]"><img src="<%=thepath & file.name%>" alt="View Full Size" width="<%=(rsGalleryConfig.Fields.Item("fldGalleryThumb").Value)%>" border="0" /></a></div></td>
                  <%
                  If intCol = 4 Then
                        %>
                        <br>
                        %>
                        intCol = 0
                  End If
            end If
      Next
                   
      For i = 0 To UBound(FoldersArray)
            if FoldersArray(i) <> "" Then
                  Recurse FoldersArray(i)                        
            Else
                  Exit For
            End if
      Next
      
End Sub
%>

Regards,

Rob.
0
coddieAuthor Commented:
Hi Rob thanks for the quick reply - But this is not doing what I need !!

I have no change to the page layout. see output below

<div class="gallery">
 
                  <td><div class="thumb"><a href="/ian/images/20/Andre30's.jpg" title="Best of the Catch !" rel="lightbox[20]"><img src="/ian/images/20/Andre30's.jpg" alt="View Full Size" width="100" border="0" /></a></div></td>
                  
                  <td><div class="thumb"><a href="/ian/images/20/fish1.jpg" title="Best of the Catch !" rel="lightbox[20]"><img src="/ian/images/20/fish1.jpg" alt="View Full Size" width="100" border="0" /></a></div></td>
                  
                  <td><div class="thumb"><a href="/ian/images/20/NeilS06.jpg" title="Best of the Catch !" rel="lightbox[20]"><img src="/ian/images/20/NeilS06.jpg" alt="View Full Size" width="100" border="0" /></a></div></td>
                  
 
 
  
   </div>

Open in new window

0
RobSampsonCommented:
Oh, have you tried without the <td> and </td> tags?  I accidentally put those in there.

Also, please make sure your folder has five or more images in it, so you can see if it outputs in four columsn.

Regards,

Rob.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

coddieAuthor Commented:
Hi Rob,
your were almost right, I managed to fix the problem by adding the following extra code
A open table<table> and table row<tr> tag before the code and a close table</tr> row and close table</table> after the code, and swaped your <br> for  close row</tr> and open row <tr> tags

Now it builds a table with 4 columns and as many rows as needed.

But thanks for the counter - that was the clue I needed to solve the problem.

Thanks.
<table><tr>
<%
Sub Recurse(Path)
      
      Dim fso, Root, WindowsFolder, Files, Folders, File, i, FoldersArray(100)
            
      Const ForReading = 1
      Set fso = Server.CreateObject("Scripting.FileSystemObject")
      Set Root = fso.getfolder(Path)
      Set Files = Root.Files
      Set Folders = Root.SubFolders
      
      intCol = 0
      For Each File In Files
            if file.name <> (rsGalleryDetail.Fields.Item("fldGalleryPic").Value) Then
                  intCol = intCol + 1
                  %>
                  <td><div class="thumb"><a href="<%=thepath & file.name%>" title="<%=(rsGalleryDetail.Fields.Item("fldGalleryTitle").Value)%>" rel="lightbox[<%=(rsGalleryDetail.Fields.Item("fldGalleryID").Value)%>]"><img src="<%=thepath & file.name%>" alt="View Full Size" width="<%=(rsGalleryConfig.Fields.Item("fldGalleryThumb").Value)%>" border="0" /></a></div></td>
                  <%
                  If intCol = 4 Then
                        %>
                       </tr><tr>
                       <%
                        intCol = 0
                  End If
            end If
      Next
                   
      For i = 0 To UBound(FoldersArray)
            if FoldersArray(i) <> "" Then
                  Recurse FoldersArray(i)                        
            Else
                  Exit For
            End if
      Next
      
End Sub
%>
 
</tr>
</table>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobSampsonCommented:
OK, no problem, that's fine.  I actually started writing code to use those <table> and <tr> tags, but then I couldn't see any existing table tags in your code, so just tried to do it with line breaks.

Anyway, well done.

Regards,

Rob.
0
coddieAuthor Commented:
Thanks for you help

Appreciated!!
0
RobSampsonCommented:
No problem. Do you want to post a request in the Community Support zone to have your comment accepted as an answer?

Regards,

Rob.
0
RobSampsonCommented:
Oh, you already did!  Silly me, I didn't scroll up! Ignore my ignorance....?!?!?

Rob.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.