Posted on 1998-10-02
Last Modified: 2013-12-25
Can anyone tell me how I could make some kind of script that creates a page with a list of links based on the files in the same directory and their titles. I use WinNT and IIS4. So I guess it could be done both in JavaScript or ASP.

Tor Olaf
Question by:toros

Expert Comment

ID: 1855408
With ASP you can use the File System Object.  I think I have some code that does that sort of thing...

Expert Comment

ID: 1855409
Crude solution, but...

With IIs, set Directory Browsing Allowed for that directory (via management console). When a browser navigates to that directory without specifying a legal file name (and a default page does not exist) the server will return a linked list of filenames.

Presenting the <TITLE> would require some scripting.
LVL 10

Accepted Solution

MasseyM earned 100 total points
ID: 1855410
Here is a program that I wrote in ASP to list all the graphics in a directory and then send them to a script so I could see how they look as backgrounds:


TH      {


<% SG = Request.QueryString("SG") %>


Set fs = CreateObject("Scripting.FileSystemObject")       'Create the FileSystemObject
If Request.QueryString("F") = "" then
      Response.Write "<FORM METHOD=GET>"
      Response.Write "Which Directory should I start in?&nbsp;<INPUT NAME=""F"" VALUE="":\"">"
      Response.Write "<INPUT TYPE=SUBMIT VALUE=""Browse Directory""><BR>"
      Response.Write "Show Graphics as Thumbnails? <INPUT TYPE=RADIO NAME=""SG"" VALUE=1> Yes | <INPUT TYPE=RADIO NAME=""SG"" VALUE=0> No"
      Response.Write "</FORM>"
      Set fold = fs.GetFolder(Request.QueryString("F"))
Response.Write ("<TABLE WIDTH='100%'>")
Response.Write ("<TR><TD>")

 Response.Write ("      <TABLE BORDER WIDTH='100%'>")
 Response.Write ("            <TH ALIGN =LEFT><A STYLE=""text-align:left;"" HREF=/>Back</A></TH>")
 Response.Write ("                  <TABLE BORDER WIDTH='100%'>")
 Response.Write ("                        <TH ALIGN = CENTER>" & fold.Path & "</TH>")
 Response.Write ("                  </TABLE>")
 Response.Write ("      </TABLE>")
 Response.Write ("</TD></TR>")

response.Write "<TABLE WIDTH='100%'><TR><TD VALIGn=TOP>"
Response.Write "<TABLE WIDTH='100%'>"
 Set foldCol = fold.SubFolders                              'Create a SubFolders collection
 For Each Y in foldCol                                    'Iterate through it
  Response.Write "<TR>"                              
  Response.Write "<TD><IMG SRC='/GRAPHICS/Folder.Gif'><A HREF=go2.asp?F=" & Y.Path
  If SG = "1" then Response.Write "&SG=1"
  Response.Write ">" &Y.Name & "</A>"
  Response.Write "</TD>"
  Response.Write "</TR>"
  Response.Write "</TABLE>"

Response.Write "</TD><TD>"

response.Write "<TABLE WIDTH='100%'>"
 Set foldCol2 = fold.Files                              'Create a Files collection
 For Each Y in foldCol2
 Cur = Cur + 1                                    'Iterate through it
  If Cur >= 6  then Response.Write "<tr>"      
  Response.Write "<td WIDTH='20%'>"
If Right(Y.Path,3) = "gif" or Right(Y.Path,3) = "jpg" then
  If SG = "1" then
      Response.Write "<IMG WIDTH =50 HEIGHT=50  SRC=" & Y.Path &" ><BR>"
  End If
  Response.Write "<A HREF=ViewasBG.asp?G=" & Y.Path
  If SG = "1" then Response.Write "&SG=1"
  Response.Write ">" &Y.Name & "</A>"            'Print the files name
End If
  Response.Write "</td>"
  If Cur >= 5 then
      Response.Write "</tr>"
      Cur = 0
  End If
 Response.Write "</table>"
 For Each Y in foldCol                                    'Now lets iterate through the folder collection again
Response.Write "</TABLE>"
Response.Write "</TD></TR></TABLE>"
End If

<% Graphic = Request.QueryString("G") %>
<% UT = Request.QueryString("UT") %>
<% UT = 1 %>
<% If UT = "1" then %>
<% ML=Request.QueryString("ML") %>
<!-- #Include Virtual="/Sample.Asp"-->
<% End If %>
Set fs = CreateObject("Scripting.FileSystemObject")


anything you want.. I use all the colors so I can see how they look against the background..


Author Comment

ID: 1855411
Thanks. It gave me some ideas about how to solve it. If somebody's interrested, a solution that works follows :



PRIVATE sub intoFold(newfold)

 set fold = fileSYSObj.GetFolder(newfold)                  
 Set foldCol2 = fold.Files                              
For Each Y in foldCol2                                    
      Response.Write "<A HREF='" & newfold & "\" & Y.Name & "'>"            
      ReadAllTextFile(newfold & "\" & Y.Name)
end sub

Function ReadAllTextFile(FilePath)
  Const ForReading = 1, ForWriting = 2
  Dim fso, f
  Set fso = CreateObject("Scripting.FileSystemObject")
  Set f = fso.OpenTextFile(FilePath, ForReading)
  ReadAllTextFile =  f.ReadAll
End Function

Function WriteTitle(Text)
      Dim MyString,MyString2
      MyString = Split(Text, "<TITLE>", -1, 1)
      ' MyString(0) contains Trash.
      ' MyString(1) contains the next splitstring.
      MyString2 = Split(MyString(1),"</TITLE>",-1,1)
      ' MyString2(0) contains the title
      Response.Write MyString2(0) & "</A><BR>"
End Function

Set fileSYSObj = CreateObject("Scripting.FileSystemObject")       

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now