File and Folder Listing.

C

Chris

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 :)
 
E

Evertjan.

=?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>"
....
 
C

Chris

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.
 
J

Jeff Cochran

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
 
C

Chris

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.
 
C

Chris

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.
 
C

Chris

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.
 
J

Jeff Cochran

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



 
C

Chris

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>
 
J

Jeff Cochran

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 said:
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
 
C

Chris

Hi Jeff,

That has worked perfectly!! Thankyou very much :)

Kind Regards,

Chris

Jeff Cochran said:
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 said:
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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top