KAbbott
asked on
How to display list of files in a directory?
Hi,
My ISP doesn't allow me to browse directorys on the server, but I want visitors to my site to be able to view all files contained with a directory and allow them to download them.
Is there a way (using javascript) of allowing me to do this? The files will have random names so there will be no way to determine what there called.
Thanks in advance for any help.
My ISP doesn't allow me to browse directorys on the server, but I want visitors to my site to be able to view all files contained with a directory and allow them to download them.
Is there a way (using javascript) of allowing me to do this? The files will have random names so there will be no way to determine what there called.
Thanks in advance for any help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NOTE!!!! MY CODE ABOVE GOT SOME LOGIC ERROR. Use the below code instead.
<%
Dim objFSO
Dim objFolder, objFile, objSFolder
Dim thisFolder
Dim strFolder
Set objFSO = Server.CreateObject("Scrip ting.FileS ystemObjec t")
thisFolder = "c:\windows\profiles\hongj un\desktop "
Set objFolder = objFSO.GetFolder(thisFolde r)
' display directory
Response.Write "<b>Directories</b><BR>"
For Each strFolder In objFolder.SubFolders
Response.Write strFolder & "<BR>"
Next
Response.Write "<BR>"
' display files
Response.Write "<b>Files</b><BR>"
For Each objFile In objFolder.Files
Response.Write " <a href='" & thisFolder & "\" & objFile.Name & "'>" & objFile.Name & "</a>"
Response.Write "<BR>"
Next
%>
hongjun
<%
Dim objFSO
Dim objFolder, objFile, objSFolder
Dim thisFolder
Dim strFolder
Set objFSO = Server.CreateObject("Scrip
thisFolder = "c:\windows\profiles\hongj
Set objFolder = objFSO.GetFolder(thisFolde
' display directory
Response.Write "<b>Directories</b><BR>"
For Each strFolder In objFolder.SubFolders
Response.Write strFolder & "<BR>"
Next
Response.Write "<BR>"
' display files
Response.Write "<b>Files</b><BR>"
For Each objFile In objFolder.Files
Response.Write " <a href='" & thisFolder & "\" & objFile.Name & "'>" & objFile.Name & "</a>"
Response.Write "<BR>"
Next
%>
hongjun
ASKER
ISP doesn't support ASP,
Is it possible to do it with client-side javascript?
Is it possible to do it with client-side javascript?
I am reasonably sure that you can not do that as JavaScript fires client-side.
Fritz the Blank
Fritz the Blank
ASKER
Dam!
If I gave all the files that where uploaded to the site .html extensions, is there a way I could see them then.
The files that I upload are only text files.
If I gave all the files that where uploaded to the site .html extensions, is there a way I could see them then.
The files that I upload are only text files.
It makes no difference about the extension type. It is an issue of client-side code not being able to list server-side directory items.
Fritz the Blank
Fritz the Blank
Change your web server to one that support asp script or one that actually allows you to do directory listing.
hongjun
hongjun
or advise your hosting co. to start using Apache. there seems to be a prob with the server and not the isp.
Most ISP's won't allow directory browsing for security reasons. Displaying directory and file information via server-side script is preferable as it allows tighter control over what can and can't be viewed.
Fritz the Blank
Fritz the Blank
well, we have no such isp's in india atleast,
anyway do i owe u some points ? :-)
anyway do i owe u some points ? :-)
Why the grade of B? Just because the answer is not what you want to hear, it doesn't make it any less right. Indeed, you could have spent days trying to code a solution that wouldn't work, and my answer (among others here) saved you that aggrevation.
Fritz the Blank
Fritz the Blank
<%
Dim objFSO
Dim objFolder, objFile, objSFolder
Dim thisFolder
Dim strFolder
Set objFSO = Server.CreateObject("Scrip
thisFolder = "c:\windows\profiles\hongj
Set objFolder = objFSO.GetFolder(thisFolde
' display directory
Response.Write "<b>Directories</b><BR>"
For Each strFolder In objFolder.SubFolders
Response.Write strFolder & "<BR>"
Next
Response.Write "<BR>"
' display files
Response.Write "<b>Files</b><BR>"
For Each objFile In objFolder.Files
Response.Write " <a href='" & objFile.Name & "'>" & objFile.Name & "</a>"
Response.Write "<BR>"
Next
%>
However, note that it is not possible to download .asp. This is because it will be run on the server before returning you the download. So, you actually download the html source of the asp returned by the server.
hongjun