I need help with the following code. I use it to list the files in a directory. How can I prevent specific files (for example index.asp etc.) from being listed?
Thanks in advance for any help!
<%
folder = "/"
If Left(server.mappath("."),1) = "/" Then
strslash = "/"
Else
strslash = "\"
End If
servername = Request.Servervariables("server_name")
scriptpath = Request.Servervariables("script_name")
scriptpath = Mid(scriptpath,(Instrrev(scriptpath, "/")),1)
Dim filesobj, fileslist, fname, posnumright
dim f, dflm
Set filesobj = Server.CreateObject("scripting.filesystemobject")
Set fileslist = filesobj.GetFolder(server.mappath(".") & "/" & folder)
%>
<table border=0 width="98%" cellspacing=0 cellpadding=0 align=center>
<tr><td>
</td></tr>
<tr>
<td>
<table border=0 width="100%" cellspacing="1" cellpadding="4">
<tr>
<td align="center">File Name</td>
<td align="center">File Date</td>
<td align="center">File Size</td>
</tr>
<%
For each thing In fileslist.files
posnumright = instrrev(thing, strslash)
fname = right(thing,(len(thing)-posnumright))
Set f = filesobj.GetFile(thing)
fdlm = f.datelastmodified
If f.size > 1023 Then
fsize = CStr(CInt(f.size / 1024)) & "k"
Else
fsize = CStr(f.size) & " bytes"
End If
physicalpath = server.mappath(".")
%>
<tr>
<td>
<a href="http://<%=servername & scriptpath & "files/" & Server.HTMLEncode(fname) %>" title="<%=Server.HTMLEncode(fname) %>" target="_blank"><%=Server.HTMLEncode(fname)%></a>
</td>
<td>
<%=Server.HTMLEncode(fdlm)%></td>
<td>
<%= Server.HTMLEncode(fsize) %>
</td>
</tr>
<%
Set f = Nothing
Next
Set fileslist = Nothing
Set filesobj = Nothing
%>
</table>
</td></tr></table>