File and Folder Listing.

Discussion in 'ASP General' started by Chris, Nov 4, 2004.

  1. Chris

    Chris Guest

    Hi,

    Not sure if this is the right forum, but hopefully someone can help me.

    I am creating something for our intranet and i want to list the files and
    folders of a directory, i found some code to do this.

    The only problem is that it lists the asp file used to for example if i go to:
    "http://myserver/listing.asp" In the file listing will be "listing.asp"
    amongst a lot of marketing documents.

    Is there a way to block/stop this one file from being listed?

    Thanks :)
     
    Chris, Nov 4, 2004
    #1
    1. Advertising

  2. Chris

    Evertjan. Guest

    =?Utf-8?B?Q2hyaXM=?= wrote on 04 nov 2004 in
    microsoft.public.inetserver.asp.general:
    > Not sure if this is the right forum, but hopefully someone can help
    > me.
    >
    > I am creating something for our intranet and i want to list the files
    > and folders of a directory, i found some code to do this.
    >
    > The only problem is that it lists the asp file used to for example if
    > i go to: "http://myserver/listing.asp" In the file listing will be
    > "listing.asp" amongst a lot of marketing documents.
    >
    > Is there a way to block/stop this one file from being listed?


    sure, =?U tf-8?B?Q2hyaXM=?=:

    ....
    if dbData("file")<>"listing.asp" response.write dbData("file") & "<br>"
    ....



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress,
    but let us keep the discussions in the newsgroup)
     
    Evertjan., Nov 4, 2004
    #2
    1. Advertising

  3. Chris

    Chris Guest

    Hi Evertjan,

    Many thanks for your response, unfortunately i cannot get it to work :(

    Below is the code I have downloaded to list the files, Where about's should
    i use your code as it says "Expecting Then" when i insert it.

    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

    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

    Next 'objItem

    Many Thanks :)

    Chris.

    "Evertjan." wrote:

    > =?Utf-8?B?Q2hyaXM=?= wrote on 04 nov 2004 in
    > microsoft.public.inetserver.asp.general:
    > > Not sure if this is the right forum, but hopefully someone can help
    > > me.
    > >
    > > I am creating something for our intranet and i want to list the files
    > > and folders of a directory, i found some code to do this.
    > >
    > > The only problem is that it lists the asp file used to for example if
    > > i go to: "http://myserver/listing.asp" In the file listing will be
    > > "listing.asp" amongst a lot of marketing documents.
    > >
    > > Is there a way to block/stop this one file from being listed?

    >
    > sure, =?U tf-8?B?Q2hyaXM=?=:
    >
    > ....
    > if dbData("file")<>"listing.asp" response.write dbData("file") & "<br>"
    > ....
    >
    >
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress,
    > but let us keep the discussions in the newsgroup)
    >
    >
     
    Chris, Nov 4, 2004
    #3
  4. Chris

    Jeff Cochran Guest

    On Thu, 4 Nov 2004 04:14:01 -0800, "Chris"
    <> wrote:

    >Hi,
    >
    >Not sure if this is the right forum, but hopefully someone can help me.
    >
    >I am creating something for our intranet and i want to list the files and
    >folders of a directory, i found some code to do this.
    >
    >The only problem is that it lists the asp file used to for example if i go to:
    >"http://myserver/listing.asp" In the file listing will be "listing.asp"
    >amongst a lot of marketing documents.
    >
    >Is there a way to block/stop this one file from being listed?


    Yes. :)

    The best method may be to organize your data better, so the files that
    need to be listed are the only ones in the folders. But you can
    always use an IF/THEN to exclude anything you wish. For example:

    IF Filename <> "listing.asp" THEN
    { Display the file in the list }
    END IF

    Or even:

    IF UCASE(RIGHT(Filename,3)) <> "ASP" THEN

    To select anything without an ASP extension.

    Jeff
     
    Jeff Cochran, Nov 4, 2004
    #4
  5. Chris

    Chris Guest

    Hi Jeff,

    I agree with you, but i need to have the file in the actual folder for IIS
    to pick it up as the default file. So i want to restrict users from being
    able to download the ASP file by not displaying it in the list of files.

    I'm not having much luck getting it to exclude the file, i tried your code
    and i got it to acknowledge the file exsisted but it still displayed it.

    Do you know of a better way to list the files and subdirectories than i am
    doing now?

    Thanks :)

    Chris.

    "Jeff Cochran" wrote:

    > On Thu, 4 Nov 2004 04:14:01 -0800, "Chris"
    > <> wrote:
    >
    > >Hi,
    > >
    > >Not sure if this is the right forum, but hopefully someone can help me.
    > >
    > >I am creating something for our intranet and i want to list the files and
    > >folders of a directory, i found some code to do this.
    > >
    > >The only problem is that it lists the asp file used to for example if i go to:
    > >"http://myserver/listing.asp" In the file listing will be "listing.asp"
    > >amongst a lot of marketing documents.
    > >
    > >Is there a way to block/stop this one file from being listed?

    >
    > Yes. :)
    >
    > The best method may be to organize your data better, so the files that
    > need to be listed are the only ones in the folders. But you can
    > always use an IF/THEN to exclude anything you wish. For example:
    >
    > IF Filename <> "listing.asp" THEN
    > { Display the file in the list }
    > END IF
    >
    > Or even:
    >
    > IF UCASE(RIGHT(Filename,3)) <> "ASP" THEN
    >
    > To select anything without an ASP extension.
    >
    > Jeff
    >
     
    Chris, Nov 4, 2004
    #5
  6. Chris

    Chris Guest

    Hi Jeff,

    I agree with you, but i need to have the file in the actual folder for IIS
    to pick it up as the default file. So i want to restrict users from being
    able to download the ASP file by not displaying it in the list of files.

    I'm not having much luck getting it to exclude the file, i tried your code
    and i got it to acknowledge the file exsisted but it still displayed it.

    Do you know of a better way to list the files and subdirectories than i am
    doing now?

    Thanks :)

    Chris.

    "Jeff Cochran" wrote:

    > On Thu, 4 Nov 2004 04:14:01 -0800, "Chris"
    > <> wrote:
    >
    > >Hi,
    > >
    > >Not sure if this is the right forum, but hopefully someone can help me.
    > >
    > >I am creating something for our intranet and i want to list the files and
    > >folders of a directory, i found some code to do this.
    > >
    > >The only problem is that it lists the asp file used to for example if i go to:
    > >"http://myserver/listing.asp" In the file listing will be "listing.asp"
    > >amongst a lot of marketing documents.
    > >
    > >Is there a way to block/stop this one file from being listed?

    >
    > Yes. :)
    >
    > The best method may be to organize your data better, so the files that
    > need to be listed are the only ones in the folders. But you can
    > always use an IF/THEN to exclude anything you wish. For example:
    >
    > IF Filename <> "listing.asp" THEN
    > { Display the file in the list }
    > END IF
    >
    > Or even:
    >
    > IF UCASE(RIGHT(Filename,3)) <> "ASP" THEN
    >
    > To select anything without an ASP extension.
    >
    > Jeff
    >
     
    Chris, Nov 4, 2004
    #6
  7. Chris

    Chris Guest

    Hi Jeff,

    I agree with you, but i need to have the file in the actual folder for IIS
    to pick it up as the default file. So i want to restrict users from being
    able to download the ASP file by not displaying it in the list of files.

    I'm not having much luck getting it to exclude the file, i tried your code
    and i got it to acknowledge the file exsisted but it still displayed it.

    Do you know of a better way to list the files and subdirectories than i am
    doing now?

    Thanks :)

    Chris.

    "Jeff Cochran" wrote:

    > On Thu, 4 Nov 2004 04:14:01 -0800, "Chris"
    > <> wrote:
    >
    > >Hi,
    > >
    > >Not sure if this is the right forum, but hopefully someone can help me.
    > >
    > >I am creating something for our intranet and i want to list the files and
    > >folders of a directory, i found some code to do this.
    > >
    > >The only problem is that it lists the asp file used to for example if i go to:
    > >"http://myserver/listing.asp" In the file listing will be "listing.asp"
    > >amongst a lot of marketing documents.
    > >
    > >Is there a way to block/stop this one file from being listed?

    >
    > Yes. :)
    >
    > The best method may be to organize your data better, so the files that
    > need to be listed are the only ones in the folders. But you can
    > always use an IF/THEN to exclude anything you wish. For example:
    >
    > IF Filename <> "listing.asp" THEN
    > { Display the file in the list }
    > END IF
    >
    > Or even:
    >
    > IF UCASE(RIGHT(Filename,3)) <> "ASP" THEN
    >
    > To select anything without an ASP extension.
    >
    > Jeff
    >
     
    Chris, Nov 4, 2004
    #7
  8. Chris

    Jeff Cochran Guest

    On Thu, 4 Nov 2004 06:26:03 -0800, "Chris"
    <> wrote:

    >I agree with you, but i need to have the file in the actual folder for IIS
    >to pick it up as the default file. So i want to restrict users from being
    >able to download the ASP file by not displaying it in the list of files.
    >
    >I'm not having much luck getting it to exclude the file, i tried your code
    >and i got it to acknowledge the file exsisted but it still displayed it.
    >
    >Do you know of a better way to list the files and subdirectories than i am
    >doing now?


    Since you didn't post what you're doing now, I have no idea. I use
    the FileSystemObject and the Files collection to list files.

    Perhaps if you show your code we can help. Or take a look at:

    http://www.darkfalz.com/1069
    http://www.darkfalz.com/1042

    Jeff




    >> On Thu, 4 Nov 2004 04:14:01 -0800, "Chris"
    >> <> wrote:
    >>
    >> >Hi,
    >> >
    >> >Not sure if this is the right forum, but hopefully someone can help me.
    >> >
    >> >I am creating something for our intranet and i want to list the files and
    >> >folders of a directory, i found some code to do this.
    >> >
    >> >The only problem is that it lists the asp file used to for example if i go to:
    >> >"http://myserver/listing.asp" In the file listing will be "listing.asp"
    >> >amongst a lot of marketing documents.
    >> >
    >> >Is there a way to block/stop this one file from being listed?

    >>
    >> Yes. :)
    >>
    >> The best method may be to organize your data better, so the files that
    >> need to be listed are the only ones in the folders. But you can
    >> always use an IF/THEN to exclude anything you wish. For example:
    >>
    >> IF Filename <> "listing.asp" THEN
    >> { Display the file in the list }
    >> END IF
    >>
    >> Or even:
    >>
    >> IF UCASE(RIGHT(Filename,3)) <> "ASP" THEN
    >>
    >> To select anything without an ASP extension.
    >>
    >> Jeff
    >>
     
    Jeff Cochran, Nov 4, 2004
    #8
  9. Chris

    Chris Guest

    Hi Jeff,

    I have included the entire ASP page i am using hopefilly this can help, Many
    Thanks :)

    <%' 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><A HREF="/">[To Parent Directory]</A><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

    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

    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">&nbsp;<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>
     
    Chris, Nov 4, 2004
    #9
  10. Chris

    Jeff Cochran Guest

    On Thu, 4 Nov 2004 08:40:14 -0800, "Chris"
    <> 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><A HREF="/">[To Parent Directory]</A><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">&nbsp;<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>
     
    Jeff Cochran, Nov 4, 2004
    #10
  11. Chris

    Chris Guest

    Hi Jeff,

    That has worked perfectly!! Thankyou very much :)

    Kind Regards,

    Chris

    "Jeff Cochran" wrote:

    > On Thu, 4 Nov 2004 08:40:14 -0800, "Chris"
    > <> 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><A HREF="/">[To Parent Directory]</A><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>

    >
    >
     
    Chris, Nov 5, 2004
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dan
    Replies:
    7
    Views:
    18,601
    catherine sea
    Oct 28, 2010
  2. Seok Bee

    Folder Access Listing

    Seok Bee, Jun 29, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    322
    Seok Bee
    Jun 29, 2006
  3. Jochen Brenzlinger
    Replies:
    5
    Views:
    958
    Roedy Green
    Sep 2, 2011
  4. eoghan

    listing folder contents

    eoghan, Mar 8, 2008, in forum: Ruby
    Replies:
    1
    Views:
    91
    Sandor Szücs
    Apr 12, 2008
  5. Joseph

    Dynamic Folder Listing

    Joseph, Mar 13, 2008, in forum: Javascript
    Replies:
    3
    Views:
    133
    Thomas 'PointedEars' Lahn
    Mar 15, 2008
Loading...

Share This Page