[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

FileSystemObject - Horizontal Loop

Posted on 2008-02-06
9
Medium Priority
?
495 Views
Last Modified: 2012-08-13
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

0
Comment
Question by:coddie
  • 5
  • 3
8 Comments
 
LVL 65

Assisted Solution

by:RobSampson
RobSampson earned 200 total points
ID: 20836246
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
 

Author Comment

by:coddie
ID: 20836370
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 20836476
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 

Accepted Solution

by:
coddie earned 0 total points
ID: 20836568
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 20836660
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
 

Author Comment

by:coddie
ID: 20836672
Thanks for you help

Appreciated!!
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20844806
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
 
LVL 65

Expert Comment

by:RobSampson
ID: 20845831
Oh, you already did!  Silly me, I didn't scroll up! Ignore my ignorance....?!?!?

Rob.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…
Suggested Courses

613 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question