PDA

View Full Version : DIR question


Dean
05-01-2003, 07:23 PM
Hi there

Can any one help me I have this code for a directory page that lists everything in the same folder.

Is their any way to get this code to not show files that have the extion .asp .htm .html so that i can it in a image folder and it will only show the image files and zip files.

any ideas welcome.

<%
Response.Buffer = True
FileTypes = "asp,avi,bmp,css,dll,doc,exe,fla,folder,gif,inc,jpg,js,log,mdb,mp3,mpg,pdf,psd,swf,txt,xls,zip,html,h tm,xml,unknown"
StrPhysicalPath = Server.MapPath("default.asp")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(StrPhysicalPath)
Set objFolder = objFile.ParentFolder
Set objFolderFolders = objFolder.SubFolders
Set objFolderFiles = objFolder.Files
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">

<HTML>
<HEAD>
<TITLE>Intranet File Directory</TITLE>
</HEAD>
<BODY MARGINWIDTH="1" MARGINHEIGHT="1" TOPMARGIN="1" LEFTMARGIN="1">
<FONT FACE="ARIAL" SIZE="-1"><B>CURRENT DIRECTORY IS:&nbsp; <%= uCase(Server.MapPath("."))%></B></FONT><BR>
<FONT FACE="ARIAL" SIZE="-2"><B>PARENT FOLDER:&nbsp;<A HREF="../"><%=objFolder.ParentFolder%>.....</A></B></FONT>
<P>
<FONT FACE="TAHOMA" SIZE="-2"><B>FOLDERS:</B></FONT>
<HR ALIGN="left" WIDTH="760">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="760">
<TR>
<%
Counter = 0
For each FolderItem in objFolderFolders
If NOT Left(FolderItem.Name,1) = "_" Then
Counter = Counter + 1
%>
<TD ALIGN="center" WIDTH="95">
<FONT FACE="ARIAL" SIZE="-2">
<A HREF="<%=FolderItem.Name %>/" STYLE="text-decoration:none">
<IMG SRC="http://summit01s002/knowledge_base/www/images/gif/icons/folder.gif" ALT="<%=uCase(FolderItem.name)%>" BORDER="0"><BR><%= uCase(LEFT(FolderItem.name,11)) %></A>
</FONT>
</TD>
<%
If Counter MOD 8 = 0 Then response.Write "</TR><TR>"
End If
Next
%>
</TR>
</TABLE>
<HR ALIGN="left" WIDTH="760">
<P>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="760">
<TR>
<TD VALIGN="middle" ALIGN="left" COLSPAN="2"><FONT FACE="ARIAL" SIZE="-1"><B>&nbsp;NAME</B></FONT></TD>
<TD VALIGN="middle" ALIGN="left"><FONT FACE="ARIAL" SIZE="-1"><B>&nbsp;TYPE</B></FONT></TD>
<TD VALIGN="middle" ALIGN="right"><FONT FACE="ARIAL" SIZE="-1"><B>&nbsp;SIZE</B></FONT></TD>
</TR>
<%
Counter = 0
FileSize = 0
For each FileItem in objFolderFiles
GrabExtension = Split(lCase(FileItem.name),".")

If NOT uBound(GrabExtension) = 1 Then
Extension = "unknown"
Else
Extension = GrabExtension(1)
If NOT Instr(FileTypes,Extension) > 0 Then
Extension = "unknown"
End If
End If
Sizer = .7
%>
<TR>
<TD COLSPAN="4" BGCOLOR="#000000" HEIGHT="1"><IMG SRC="/icons/unknown.gif" WIDTH="1" HEIGHT="1"></TD>
</TR>
<TR onMouseover="this.bgColor='#EEEEEE'" onMouseout="this.bgColor='#FFFFFF'">
<TD VALIGN="middle" ALIGN="left" WIDTH="<%= 36*Sizer%>">
<A HREF="<%= FileItem.Name %>" STYLE="text-decoration:none">
<IMG SRC="http://summit01s002/knowledge_base/www/images/gif/icons/<%=Extension%>.gif" WIDTH="<%=36*Sizer%>" HEIGHT="<%=39*Sizer%>" ALT="<%=uCase(FileItem.name)%>" BORDER="0"></A></TD>
<TD VALIGN="middle" ALIGN="left" WIDTH="275">&nbsp;
<A HREF="<%= FileItem.Name %>" STYLE="text-decoration:none"><FONT FACE="tahoma" SIZE="-2" COLOR="0000FF"><%= uCase(FileItem.name) %></FONT></A></TD>
<TD VALIGN="middle" ALIGN="left"><FONT FACE="tahoma" SIZE="-2">&nbsp;<%= uCase(FileItem.type ) %></FONT></TD>
<TD VALIGN="middle" ALIGN="right"><FONT FACE="tahoma" SIZE="-2">&nbsp;<%= uCase(FileItem.size) %></FONT></TD>
</TR>
<%
FileSize = FileSize + cDbl(FileItem.Size)
Counter = Counter + 1
Next
%>
<TR>
<TD COLSPAN="4" BGCOLOR="#000000" HEIGHT="1"><IMG SRC="/icons/unknown.gif" WIDTH="1" HEIGHT="1"></TD>
</TR>
</TABLE>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="720">
<TR>
<TD WIDTH="720" ALIGN="RIGHT">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="255">
<TR>
<TD WIDTH="75">&nbsp;</TD>
<TD WIDTH="120" ALIGN="RIGHT" VALIGN="BOTTOM">
<FONT FACE="TAHOMA" SIZE="-2"><B>TOTAL:</B></FONT></TD>
<TD WIDTH="60" ALIGN="RIGHT" VALIGN="BOTTOM">
<FONT FACE="TAHOMA" SIZE="-2" COLOR="red"><B>&nbsp;<%=FileSize%></B></FONT></TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD ALIGN="RIGHT" VALIGN="BOTTOM">
<FONT FACE="TAHOMA" SIZE="-2"><B>FILES:</B></FONT></TD>
<TD ALIGN="RIGHT" VALIGN="BOTTOM">
<FONT FACE="TAHOMA" SIZE="-2" COLOR="red"><B>&nbsp;<%=Counter%></B></FONT></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<P>
</BODY>
</HTML>


I hope someone can help with this :confused: :confused: :confused: :confused:

oracleguy
05-01-2003, 07:41 PM
Why not in your for loop just get the extension of the file and if it isn't an image or whatever ones your want, it doesn't output any html.
strExtension=Mid(FileItem.Name,InStrRev(FileItem.Name,"."))
That should give you the extension of the file.

Dean
05-01-2003, 07:56 PM
you have to exuse me i have thick head on today it seems aunt sally has put the other head in the wash.

were i am i meant to put the line of code you have mention into the script.

could you please include the line above where i should put in and the line below so i can see it.

and then i will try it in the morning

oracleguy
05-02-2003, 04:50 AM
Originally posted by Dean


<%
Response.Buffer = True
FileTypes = "asp,avi,bmp,css,dll,doc,exe,fla,folder,gif,inc,jpg,js,log,mdb,mp3,mpg,pdf,psd,swf,txt,xls,zip,html,h tm,xml,unknown"
StrPhysicalPath = Server.MapPath("default.asp")
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(StrPhysicalPath)
Set objFolder = objFile.ParentFolder
Set objFolderFolders = objFolder.SubFolders
Set objFolderFiles = objFolder.Files
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">

<HTML>
<HEAD>
<TITLE>Intranet File Directory</TITLE>
</HEAD>
<BODY MARGINWIDTH="1" MARGINHEIGHT="1" TOPMARGIN="1" LEFTMARGIN="1">
<FONT FACE="ARIAL" SIZE="-1"><B>CURRENT DIRECTORY IS:&nbsp; <%= uCase(Server.MapPath("."))%></B></FONT><BR>
<FONT FACE="ARIAL" SIZE="-2"><B>PARENT FOLDER:&nbsp;<A HREF="../"><%=objFolder.ParentFolder%>.....</A></B></FONT>
<P>
<FONT FACE="TAHOMA" SIZE="-2"><B>FOLDERS:</B></FONT>
<HR ALIGN="left" WIDTH="760">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="760">
<TR>
<%
Counter = 0
For each FolderItem in objFolderFolders
If NOT Left(FolderItem.Name,1) = "_" Then
Counter = Counter + 1
%>
<TD ALIGN="center" WIDTH="95">
<FONT FACE="ARIAL" SIZE="-2">
<A HREF="<%=FolderItem.Name %>/" STYLE="text-decoration:none">
<IMG SRC="http://summit01s002/knowledge_base/www/images/gif/icons/folder.gif" ALT="<%=uCase(FolderItem.name)%>" BORDER="0"><BR><%= uCase(LEFT(FolderItem.name,11)) %></A>
</FONT>
</TD>
<%
If Counter MOD 8 = 0 Then response.Write "</TR><TR>"
End If
Next
%>
</TR>
</TABLE>
<HR ALIGN="left" WIDTH="760">
<P>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="760">
<TR>
<TD VALIGN="middle" ALIGN="left" COLSPAN="2"><FONT FACE="ARIAL" SIZE="-1"><B>&nbsp;NAME</B></FONT></TD>
<TD VALIGN="middle" ALIGN="left"><FONT FACE="ARIAL" SIZE="-1"><B>&nbsp;TYPE</B></FONT></TD>
<TD VALIGN="middle" ALIGN="right"><FONT FACE="ARIAL" SIZE="-1"><B>&nbsp;SIZE</B></FONT></TD>
</TR>
<%
Counter = 0
FileSize = 0
For each FileItem in objFolderFiles
Select Case strExtension=Mid(FileItem.Name,InStrRev(FileItem.Name,"."))
Case ".jpeg" or ".png" or ".gif"

GrabExtension = Split(lCase(FileItem.name),".")

If NOT uBound(GrabExtension) = 1 Then
Extension = "unknown"
Else
Extension = GrabExtension(1)
If NOT Instr(FileTypes,Extension) > 0 Then
Extension = "unknown"
End If
End If
Sizer = .7
%>
<TR>
<TD COLSPAN="4" BGCOLOR="#000000" HEIGHT="1"><IMG SRC="/icons/unknown.gif" WIDTH="1" HEIGHT="1"></TD>
</TR>
<TR onMouseover="this.bgColor='#EEEEEE'" onMouseout="this.bgColor='#FFFFFF'">
<TD VALIGN="middle" ALIGN="left" WIDTH="<%= 36*Sizer%>">
<A HREF="<%= FileItem.Name %>" STYLE="text-decoration:none">
<IMG SRC="http://summit01s002/knowledge_base/www/images/gif/icons/<%=Extension%>.gif" WIDTH="<%=36*Sizer%>" HEIGHT="<%=39*Sizer%>" ALT="<%=uCase(FileItem.name)%>" BORDER="0"></A></TD>
<TD VALIGN="middle" ALIGN="left" WIDTH="275">&nbsp;
<A HREF="<%= FileItem.Name %>" STYLE="text-decoration:none"><FONT FACE="tahoma" SIZE="-2" COLOR="0000FF"><%= uCase(FileItem.name) %></FONT></A></TD>
<TD VALIGN="middle" ALIGN="left"><FONT FACE="tahoma" SIZE="-2">&nbsp;<%= uCase(FileItem.type ) %></FONT></TD>
<TD VALIGN="middle" ALIGN="right"><FONT FACE="tahoma" SIZE="-2">&nbsp;<%= uCase(FileItem.size) %></FONT></TD>
</TR>
<%
FileSize = FileSize + cDbl(FileItem.Size)
Counter = Counter + 1
End Select
Next
%>
<TR>
<TD COLSPAN="4" BGCOLOR="#000000" HEIGHT="1"><IMG SRC="/icons/unknown.gif" WIDTH="1" HEIGHT="1"></TD>
</TR>
</TABLE>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="720">
<TR>
<TD WIDTH="720" ALIGN="RIGHT">
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="255">
<TR>
<TD WIDTH="75">&nbsp;</TD>
<TD WIDTH="120" ALIGN="RIGHT" VALIGN="BOTTOM">
<FONT FACE="TAHOMA" SIZE="-2"><B>TOTAL:</B></FONT></TD>
<TD WIDTH="60" ALIGN="RIGHT" VALIGN="BOTTOM">
<FONT FACE="TAHOMA" SIZE="-2" COLOR="red"><B>&nbsp;<%=FileSize%></B></FONT></TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD ALIGN="RIGHT" VALIGN="BOTTOM">
<FONT FACE="TAHOMA" SIZE="-2"><B>FILES:</B></FONT></TD>
<TD ALIGN="RIGHT" VALIGN="BOTTOM">
<FONT FACE="TAHOMA" SIZE="-2" COLOR="red"><B>&nbsp;<%=Counter%></B></FONT></TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<P>
</BODY>
</HTML>


Try that, it should work and you can add as many file extensions as you'd like.

Dean
05-02-2003, 09:38 AM
hi there i copied the text you sent to me and when i ran the code i got this error.

FOLDERS:


--------------------------------------------------------------------------------


--------------------------------------------------------------------------------

NAME TYPE SIZE
Microsoft VBScript runtime error '800a000d'
Type mismatch: '[string: "jpg"]'

/summit_upload/www/upload1/editor_images/dir.asp, line 56


any idea's
:confused: