Forum Moderators: open
So how can I create some sort of exception, so that it checks for .asp, .html files and does not display those?
Or, alternatively, change the script so that it does not list files (but still lists folders) that are in the parent directory?
<% OPTION EXPLICIT %>
<% sub ListFolderContents(path)
dim fs, folder, file, item, url
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path) 'Display the target folder and info.
Response.Write("<li><strong>" & folder.Name & "</strong> " )
Response.Write("<ul>" & vbCrLf)
'Display a list of sub folders.
for each item in folder.SubFolders
ListFolderContents(item.Path)
next
'Display a list of files.
for each item in folder.Files
url = MapURL(item.path)
Response.Write("<li><a href=""" & url & """>" & item.Name & "</a> </li>" & vbCrLf)
next
Response.Write("</ul>" & vbCrLf)
Response.Write("</li>" & vbCrLf)
end sub
function MapURL(path)
dim rootPath, url
'Convert a physical file path to a URL for hypertext links.
rootPath = Server.MapPath("/")
url = Right(path, Len(path) - Len(rootPath))
MapURL = Replace(url, "\", "/")
end function %>
[edited by: Darkelve at 8:40 am (utc) on April 8, 2008]
<% OPTION EXPLICIT %>
<% sub ListFolderContents(path)
dim fs, folder, file, item, url
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)
' Output Only Folders Flag
dim bFoldersOnly
bFoldersOnly = False
' File extension exclusion list
' Currently excluding HTML files
' Comma required to seperate file extensions
dim sFileExclusions
dim sExtension
sFileExclusions = "HTML,HTM,"
'Display the target folder and info.
Response.Write("<li><strong>" & folder.Name & "</strong> " )
Response.Write("<ul>" & vbCrLf)
'Display a list of sub folders.
for each item in folder.SubFolders
ListFolderContents(item.Path)
next
'Display a list of files.
If NOT(bFoldersOnly) Then
for each item in folder.Files
sExtension = UCase(Right(item.name,len(item.name)-InStrRev(item.name, ".")))
If (InStr(sFileExclusions, sExtension)=0) Then
url = MapURL(item.path)
Response.Write("<li><a href=""" & url & """>" & item.Name & "</a> </li>" & vbCrLf)
End If
next
End If
Response.Write("</ul>" & vbCrLf)
Response.Write("</li>" & vbCrLf)
end sub
function MapURL(path)
dim rootPath, url
'Convert a physical file path to a URL for hypertext links.
rootPath = Server.MapPath("/")
url = Right(path, Len(path) - Len(rootPath))
MapURL = Replace(url, "\", "/")
end function %>