Re: File and Folder Listing.
From: Jeff Cochran (jeff.nospam_at_zina.com)
Date: 11/04/04
- Next message: Ray Costanzo [MVP]: "Re: dialog message displays on server"
- Previous message: Aaron [SQL Server MVP]: "Re: ASP app IE errors with Win 2003"
- In reply to: Chris: "Re: File and Folder Listing."
- Next in thread: Chris: "Re: File and Folder Listing."
- Reply: Chris: "Re: File and Folder Listing."
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 04 Nov 2004 20:07:12 GMT
On Thu, 4 Nov 2004 08:40:14 -0800, "Chris"
<Chris@discussions.microsoft.com> wrote:
>Hi Jeff,
>
>I have included the entire ASP page i am using hopefilly this can help, Many
>Thanks :)
Okay, I hate using a recordset like this, but if you scroll down
you'll find changes that will skip your ASP file.
Jeff
><%' Now to the Runtime code:
>Dim strPath 'Path of directory to show
>Dim objFSO 'FileSystemObject variable
>Dim objFolder 'Folder variable
>Dim objItem 'Variable used to loop through the contents of the folder
>
>' A recordset object variable and some selected constants from adovbs.inc.
>' I use these for the sorting code.
>Dim rstFiles
>Const adVarChar = 200
>Const adInteger = 3
>Const adDate = 7
>
>
>' You could just as easily read this from some sort of input, but I don't
>' need you guys and gals roaming around our server so I've hard coded it to
>' a directory I set up to illustrate the sample.
>' NOTE: As currently implemented, this needs to end with the /
>strPath = "/"
>
>' Create our FSO
>Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
>
>' Get a handle on our folder
>Set objFolder = objFSO.GetFolder(Server.MapPath(strPath))
>
>' Show a little description line and the title row of our table
>%>
>
>
>
><pre><H1 align="center"><font size="5">Contents of <strong><%= strPath
>%></strong></H1></font>[To Parent Directory]<br><br>
>
><table border="1" width="100%" bordercolor="green" cellspacing="0"
>cellpadding="2">
> <tr bgcolor="1">
> <td><font face="Verdana, Arial, Times New Roman" color="#FFFFFF"><b>File
>Name:</b></font></td>
> <td><font face="Verdana, Arial, Times New Roman" color="#FFFFFF"><b>File
>Size (bytes):</b></font></td>
> <td><font face="Verdana, Arial, Times New Roman"color="#FFFFFF"><b>Date
>Created:</b></font></td>
> <td><font face="Verdana, Arial, Times New Roman"color="#FFFFFF"><b>File
>Type:</b></font></td>
> </tr>
><%
>
>' First I deal with any subdirectories. I just display them and when you
>' click you go to them via plain HTTP. You might want to loop them back
>' through this file once you've set it up to take a path as input. It seems
>' like the logical thing to do to me at least!
>For Each objItem In objFolder.SubFolders
> ' Deal with the stupid VTI's that keep giving our visitors 404's
> If InStr(1, objItem, "_vti", 1) = 0 Then
> %>
> <tr>
>
> <td align="left" ><font face="Tahoma, Verdana, Arial, Times New Roman"
>color="#FFFFFF"> <a href="<%= strPath & objItem.Name %>"><%= objItem.Name
>%></a></td>
> <td align="right"><font face="Tahoma, Verdana, Arial, Times New Roman"
>color="#FFFFFF"><%= objItem.Size %></td>
> <td align="left" ><font face="Tahoma, Verdana, Arial, Times New Roman"
>color="#FFFFFF"><%= objItem.DateCreated %></td>
> <td align="left" ><font face="Tahoma, Verdana, Arial, Times New Roman"
>color="#FFFFFF"><%= objItem.Type %></td>
></font>
></tr>
> <%
> End If
>Next 'objItem
>
>' Now that I've done the SubFolders, do the files!
>
>' In order to be able to sort them easily and still close the FSO relatively
>' quickly I'm going to make use of an ADO Recordset object with no attached
>' datasource. While it does have a slightly greater overhead then an array
>' or dictionary object, it gives me named access to the fields and has built
>' in sorting functionality.
>Set rstFiles = Server.CreateObject("ADODB.Recordset")
>
>rstFiles.Fields.Append "name", adVarChar, 255
>rstFiles.Fields.Append "size", adInteger
>rstFiles.Fields.Append "date", adDate
>rstFiles.Fields.Append "type", adVarChar, 255
>rstFiles.Open
>
>For Each objItem In objFolder.Files
IF rstFiles.Fields("name").Value <> "filelist.asp" THEN
>
> rstFiles.AddNew
> rstFiles.Fields("name").Value = objItem.Name
> rstFiles.Fields("size").Value = objItem.Size
> rstFiles.Fields("date").Value = objItem.DateCreated
> rstFiles.Fields("type").Value = objItem.Type
END IF
>
>Next 'objItem
>
>' All done! Kill off our File System Object variables.
>Set objItem = Nothing
>Set objFolder = Nothing
>Set objFSO = Nothing
>
>' Now we can sort our data and display it:
>
>' Sort ascending by size and secondarily descending by date
>' (by date is mainly for illustration since all our files
>' are different sizes)
>rstFiles.Sort = "size ASC, date DESC"
>
>rstFiles.MoveFirst
>
>Do While Not rstFiles.EOF
> %>
> <tr>
> <td align="left" ><Font face="Verdana, Arial, Times New Roman"> <a
>href="<%= strPath & rstFiles.Fields("name").Value %>"><%=
>rstFiles.Fields("name").Value %></a></td>
> <td align="right"><Font face="Tahoma,Verdana, Arial, Times New Roman"><%=
>rstFiles.Fields("size").Value %></td>
> <td align="left" ><Font face="Tahoma,Verdana, Arial, Times New Roman"><%=
>rstFiles.Fields("date").Value %></td>
> <td align="left" ><Font face="Tahoma,Verdana, Arial, Times New Roman"><%=
>rstFiles.Fields("type").Value %></td>
> </font>
> </tr>
> <%
> rstFiles.MoveNext
>Loop
>
>' Close our ADO Recordset object
>rstFiles.Close
>Set rstFiles = Nothing
>
>'Close the table
>%>
></table>
>
><p align="Center"><b><Font size="4" face="Tahoma,Verdana, Arial, Times New
>Roman">Your IP Address has been logged & actions monitored, abuse will be
>reported and acted upon.</font></b></p>
- Next message: Ray Costanzo [MVP]: "Re: dialog message displays on server"
- Previous message: Aaron [SQL Server MVP]: "Re: ASP app IE errors with Win 2003"
- In reply to: Chris: "Re: File and Folder Listing."
- Next in thread: Chris: "Re: File and Folder Listing."
- Reply: Chris: "Re: File and Folder Listing."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|