Hi,
I have the following code to list contents of a folder. I need to know the code to do the following:
1/. change the code so that it doesn't show the file "default.asp" or the folder "Images".
2/. Seperate from above I need to know how I WOULD SHOW ONLY the file "index.htm"
could some one help, thanks very much:
<%@LANGUAGE="VBSCRIPT"%>
<%
Option Explicit
On Error Resume Next
' this section is optional - it just denies anonymous access
If Request.ServerVariables("LOGON_USER"="" Then
Response.Status = "401 Access Denied"
End If
' declare variables
Dim objFSO, objFolder
Dim objCollection, objItem
Dim strPhysicalPath, strTitle, strServerName
Dim strPath, strTemp
Dim strName, strFile, strExt, strAttr
Dim intSizeB, intSizeK, intAttr, dtmDate
' declare constants
Const vbReadOnly = 1
Const vbHidden = 2
Const vbSystem = 4
Const vbVolume = 8
Const vbDirectory = 16
Const vbArchive = 32
Const vbAlias = 64
Const vbCompressed = 128
' don't cache the page
Response.AddHeader "Pragma", "No-Cache"
Response.CacheControl = "Private"
' get the current folder URL path
strTemp = Mid(Request.ServerVariables("URL",2)
strPath = ""
Do While Instr(strTemp,"/"
strPath = strPath & Left(strTemp,Instr(strTemp,"/")
strTemp = Mid(strTemp,Instr(strTemp,"/"+1)
Loop
strPath = "/" & strPath
' build the page title
strServerName = UCase(Request.ServerVariables("SERVER_NAME")
strTitle = "Contents of the " & strPath & " folder"
' create the file system objects
strPhysicalPath = Server.MapPath(strPath)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
Set objFolder = objFSO.GetFolder(strPhysicalPath)
%>
<html>
<head>
<title><%=strServerName%> - <%=strTitle%></title>
<meta name="GENERATOR" content="The Mighty Hand of Bob">
</head>
<body bgcolor="#FFFFFF">
<table width="906" border="0" cellspacing="0" cellpadding="0" height="26">
<tr>
<td width="283"><img src="/images/coatbridge.gif" width="208" height="69"></td>
<td width="378">
<div align="center"><img src="/NLN_Materials/Images/NLNMDIT.gif" width="120" height="100"></div>
</td>
<td width="245"> </td>
</tr>
</table>
<h1 align="left"> </h1>
<div align="center"><center>
<table width="40%" border="1" cellspacing="1" cellpadding="2" bordercolor="#CCCCCC">
<tr>
<th align="left" bgcolor="#003366"><font color="#FFFFFF">Course Material:</font></th>
</tr>
<%
''''''''''''''''''''''''''''''''''''''''
' output the folder list
''''''''''''''''''''''''''''''''''''''''
Set objCollection = objFolder.SubFolders
For Each objItem in objCollection
strName = objItem.Name
strAttr = MakeAttr(objItem.Attributes)
dtmDate = CDate(objItem.DateLastModified)
%>
<tr>
<td align="left"><b><a href="<%=strName%>"><%=strName%></a></b></td>
</tr>
<% Next %>
<%
''''''''''''''''''''''''''''''''''''''''
' output the file list
''''''''''''''''''''''''''''''''''''''''
Set objCollection = objFolder.Files
For Each objItem in objCollection
strName = objItem.Name
strFile = Server.HTMLEncode(Lcase(strName))
intSizeB = objItem.Size
intSizeK = Int((intSizeB/1024) + .5)
If intSizeK = 0 Then intSizeK = 1
strAttr = MakeAttr(objItem.Attributes)
strName = Ucase(objItem.ShortName)
If Instr(strName,"." Then strExt = Right(strName,Len(strName)-Instr(strName,".") Else strExt = ""
dtmDate = CDate(objItem.DateLastModified)
%>
<tr>
<td align="left"><a href="<%=strFile%>"><%=strFile%></a></td>
</tr>
<% Next %>
</table>
</center></div>
</body>
</html>
<%
Set objFSO = Nothing
Set objFolder = Nothing
' this adds the IIf() function to VBScript
Function IIf(i,j,k)
If i Then IIf = j Else IIf = k
End Function
' this function creates a string from the file atttributes
Function MakeAttr(intAttr)
MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-"
MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-"
MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-"
MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-"
End Function
%>
I have the following code to list contents of a folder. I need to know the code to do the following:
1/. change the code so that it doesn't show the file "default.asp" or the folder "Images".
2/. Seperate from above I need to know how I WOULD SHOW ONLY the file "index.htm"
could some one help, thanks very much:
<%@LANGUAGE="VBSCRIPT"%>
<%
Option Explicit
On Error Resume Next
' this section is optional - it just denies anonymous access
If Request.ServerVariables("LOGON_USER"="" Then
Response.Status = "401 Access Denied"
End If
' declare variables
Dim objFSO, objFolder
Dim objCollection, objItem
Dim strPhysicalPath, strTitle, strServerName
Dim strPath, strTemp
Dim strName, strFile, strExt, strAttr
Dim intSizeB, intSizeK, intAttr, dtmDate
' declare constants
Const vbReadOnly = 1
Const vbHidden = 2
Const vbSystem = 4
Const vbVolume = 8
Const vbDirectory = 16
Const vbArchive = 32
Const vbAlias = 64
Const vbCompressed = 128
' don't cache the page
Response.AddHeader "Pragma", "No-Cache"
Response.CacheControl = "Private"
' get the current folder URL path
strTemp = Mid(Request.ServerVariables("URL",2)
strPath = ""
Do While Instr(strTemp,"/"
strPath = strPath & Left(strTemp,Instr(strTemp,"/")
strTemp = Mid(strTemp,Instr(strTemp,"/"+1)
Loop
strPath = "/" & strPath
' build the page title
strServerName = UCase(Request.ServerVariables("SERVER_NAME")
strTitle = "Contents of the " & strPath & " folder"
' create the file system objects
strPhysicalPath = Server.MapPath(strPath)
Set objFSO = Server.CreateObject("Scripting.FileSystemObject"
Set objFolder = objFSO.GetFolder(strPhysicalPath)
%>
<html>
<head>
<title><%=strServerName%> - <%=strTitle%></title>
<meta name="GENERATOR" content="The Mighty Hand of Bob">
</head>
<body bgcolor="#FFFFFF">
<table width="906" border="0" cellspacing="0" cellpadding="0" height="26">
<tr>
<td width="283"><img src="/images/coatbridge.gif" width="208" height="69"></td>
<td width="378">
<div align="center"><img src="/NLN_Materials/Images/NLNMDIT.gif" width="120" height="100"></div>
</td>
<td width="245"> </td>
</tr>
</table>
<h1 align="left"> </h1>
<div align="center"><center>
<table width="40%" border="1" cellspacing="1" cellpadding="2" bordercolor="#CCCCCC">
<tr>
<th align="left" bgcolor="#003366"><font color="#FFFFFF">Course Material:</font></th>
</tr>
<%
''''''''''''''''''''''''''''''''''''''''
' output the folder list
''''''''''''''''''''''''''''''''''''''''
Set objCollection = objFolder.SubFolders
For Each objItem in objCollection
strName = objItem.Name
strAttr = MakeAttr(objItem.Attributes)
dtmDate = CDate(objItem.DateLastModified)
%>
<tr>
<td align="left"><b><a href="<%=strName%>"><%=strName%></a></b></td>
</tr>
<% Next %>
<%
''''''''''''''''''''''''''''''''''''''''
' output the file list
''''''''''''''''''''''''''''''''''''''''
Set objCollection = objFolder.Files
For Each objItem in objCollection
strName = objItem.Name
strFile = Server.HTMLEncode(Lcase(strName))
intSizeB = objItem.Size
intSizeK = Int((intSizeB/1024) + .5)
If intSizeK = 0 Then intSizeK = 1
strAttr = MakeAttr(objItem.Attributes)
strName = Ucase(objItem.ShortName)
If Instr(strName,"." Then strExt = Right(strName,Len(strName)-Instr(strName,".") Else strExt = ""
dtmDate = CDate(objItem.DateLastModified)
%>
<tr>
<td align="left"><a href="<%=strFile%>"><%=strFile%></a></td>
</tr>
<% Next %>
</table>
</center></div>
</body>
</html>
<%
Set objFSO = Nothing
Set objFolder = Nothing
' this adds the IIf() function to VBScript
Function IIf(i,j,k)
If i Then IIf = j Else IIf = k
End Function
' this function creates a string from the file atttributes
Function MakeAttr(intAttr)
MakeAttr = MakeAttr & IIf(intAttr And vbArchive,"A","-"
MakeAttr = MakeAttr & IIf(intAttr And vbSystem,"S","-"
MakeAttr = MakeAttr & IIf(intAttr And vbHidden,"H","-"
MakeAttr = MakeAttr & IIf(intAttr And vbReadOnly,"R","-"
End Function
%>