Click to See Complete Forum and Search --> : For each in backwards


slloyd
10-12-2004, 01:29 PM
I have a for/next loop that uses "each..in" to display a directory listing.

How do I make it go backwards?
Reverse the order?

for each objFile In objFolder.Files
&nbsp;&nbsp; Response.Write(objFile.Name + "<br>")
Next

chrismartz
10-12-2004, 08:08 PM
what do you mean backwards?

javaNoobie
10-12-2004, 11:01 PM
You will have to use a 'For' loop instead of a 'For each' loop

slloyd
10-13-2004, 11:05 AM
Oh, nevermind - I figured it out. I used the For Each In to stick the filenames in an array, and then stepped through the array in reverse. (See below)


<%@ Language=VBScript %>
<% Response.Buffer = True %>
<%
Dim objFileSystemObject, objFile, objFolder, objDrive
Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")

Dim strPathInfo
strPathInfo = Request.ServerVariables("Path_INFO")
strPhysPath = Request.ServerVariables("APPL_PHYSICAL_PATH")

dim myPath
'modify the following line with the correct current folder name
myPath = strPhysPath & "/"

dim myFolder, strTemp
Set objFolder = objFileSystemObject.GetFolder(myPath)

Response.Write("Contents of: " + objFolder.Name + "<br>")

Dim iCount
Dim filenames(100)
icount=-1
for each objFile In objFolder.Files
&nbsp;&nbsp;icount=icount +1
&nbsp;&nbsp;filenames(icount) = objfile.Name
Next

For i=icount to 0 step -1
&nbsp;&nbsp;Response.Write( "<br>" + filenames(i) )
Next
%>