Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display files all files in a folder, except for .asp page itself 1

Status
Not open for further replies.

Nogi

Technical User
Dec 10, 2004
132
BE
I have a question of which i have no idea if it can be accomplished.
The following script shows me all files that are in the folder "/here/okido/", as link on an .asp page.

Quote:

<%
dim IISFOLDER
IISFOLDER = Server.MapPath("/Here/okido/")
Dim fso, folder, File, Files, sFileDetails
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(IISFOLDER)
Set Files = folder.Files
For Each File in Files
%>
<b>
<a href = '/Partitions/Joucomatic/<%= File.Name %>' target = '_blank'> <%= File.Name %>
</a>
</b>
<br />
<%
Next
Set folder = Nothing
Set fso = Nothing
%>

Unquote

I have 2 problems:

1.: Each time i wish to use this page in another folder, i have to manually change the folders location ("here/okido/") in the script.
Is there a way to have it automatically show the files of the folder that it is in, without having to change the script all the time?

2.: if i put the asp page in the folder i wish to view the files from, it shows itself in between the files. Can this script be adjusted so it doesn't display the asp page itself?

Thanks in advance for your help
 
Firstly, ASP questions will get a better response in the ASP forum (forum333).

Having said that, I think that you can reference the current folder like so:

IISFOLDER = Server.MapPath("./")

As for not displaying the file itself, try this:

For Each File in Files
If File.Name <> "YourFileName.asp" Then
%>
<b>
<a href = '/Partitions/Joucomatic/<%= File.Name %>' target = '_blank'> <%= File.Name %></a>
</b>
<br />
<%
EndIf
Next

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Hey thanks for your response jebenson.

My excuses if i posted this question in the wrong forum.
I have indeed been mistaken.

I have adjusted the script as you said, which now looks like this:

Code:
<%
dim IISFOLDER
IISFOLDER = Server.MapPath("./")
Dim fso, folder, File, Files, sFileDetails 
Set fso = Server.CreateObject("Scripting.FileSystemObject") 
Set folder = fso.GetFolder(IISFOLDER) 
Set Files = folder.Files 
For Each File in Files
   If File.Name <> "Contents.asp" Then
      %>
        <b>
          <a href = './<%= File.Name %>' target = '_blank'>       <%= File.Name %></a>
        </b>
  <br />
<%
Endif
Next 
Set folder = Nothing 
Set fso = Nothing 
%>

The error looks like this:

Quote:

The script reported following error: Expected statement (error number 0x800A0400 hex)

In file /Partitions/joucomatic/contents.asp

on line 17, position 0 :

Endif

Unquote

You have an idea what might have caused this error?
 
I don't do much web scripting, ut I think maybe:

<a href = './<%= File.Name %>' target = '_blank'> <%= File.Name %></a>

Should be:

<a href = './<% File.Name %>' target = '_blank'> <% File.Name %></a>


Try that, but don't be surprised if it does not work. You also may need to Response.Write the filename to get it to output into the html file.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top