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!

Directory Listing

Status
Not open for further replies.

stevemarsh99

Technical User
Aug 10, 2005
88
GB
Guys, this code below displays the contents of a directly in plain text with <br> in a list:

<%
folder = "C:\Downloads"

set fso = CreateObject("Scripting.fileSystemObject")
set fold = fso.getFolder(folder)
fileCount = fold.files.count
dim fNames()
redim fNames(fileCount)
cFcount = 0
for each file in fold.files
cFcount = cFcount + 1
fNames(cFcount) = lcase(file.name)
next
for tName = 1 to fileCount
for nName = (tName + 1) to fileCount
if strComp(fNames(tName),fNames(nName),0)=1 then
buffer = fNames(nName)
fNames(nName) = fNames(tName)
fNames(tName) = buffer
end if
next
next
for i = 1 to fileCount
content = content & fNames(i) & "<br>"
next
Response.Write content
%>

How would I get these entries to appear in a list/dropdown menu with the values of the entry being equal to the actual name of the file in the directory?

In simple terms, I have a folder that holds images. I want the dropdown menu to list all the files in the folder on my server so when you select the option, the value is the name of the file.

Thanks

Steve
 
Change these lines
Code:
for i = 1 to fileCount 
        content = content & fNames(i) & "<br>" 
    next 
    Response.Write content
to
Code:
for i = 1 to fileCount 
        content = content & "<option value='" & fNames(i) & "'>" & fNames(i) & "</option>"
    next 
    Response.Write "<select name='pics'>"
    Response.Write content 
    Response.Write "</select>"

Should just about do it for you

Cheech

[Peace][Pipe]
 
Hi, i am fairly new to this dreamweaver so please be patient.
i have a situation in work were a web page is required that displays a folder contents and i thought i'd found the solution above.
When i paste the code in i get an ASP symbol, but when i preview it i just get a blank page.
i saved the page as an asp page and even installed iis on my xp machine as my but when i open the page it is still blank.
any help on what i am doing wrong will be gratefully accepted.
Thanks.
 
does your testing server have a "C:\Downloads" folder? try using server.mappath to locate the server. Also is IIS set up to run active server pages?

[Peace][Pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top