Forum Moderators: open

Message Too Old, No Replies

ASP for each/next script

How to exclude certain items?

         

pixel_juice

3:30 pm on Aug 5, 2003 (gmt 0)

10+ Year Member



I'm displaying a list of files within a directory with ASP code similar to as follows:


Dim fso
Set fso = Server.CreateObject("Scripting.FileSystemObject")

Dim rootFolder
Set rootFolder = fso.GetFolder(Server.MapPath("./."))

Dim files
Set files = rootFolder.Files

For Each file in files
Response.Write "<li><a href="""&file.Name&""">"
Response.write file.Name &" </a></li> "
Next

This works fine, however I want to exclude files containing certain strings (e.g. "index") from appearing in the list.

If any more expereinced ASP-ers out there who can give me a hand it would be greatly appreciated. All my attempts so far have resulted in 'Object not a collection' errors or similar troubles.

Iguana

3:36 pm on Aug 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hope I haven't missed the point

Can't you just wrap your Response.Write's with

If Instr(lcase(file.Name), "index") = 0 Then
End If

pixel_juice

3:57 pm on Aug 5, 2003 (gmt 0)

10+ Year Member



Thanks, that's spot on!

And sorry Iguana, bit of an ASP newbie here ;)

Plus the heat over here in the UK is draining my ability to think...

Iguana

4:21 pm on Aug 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Suffering in the same heat - managed to find myself a cut-and-paste task and I'm doing it very slowly :)