ASP Code

Display directory contents with ASP

Here's a really quick way to list the files & folders in a directory with ASP. This code uses the FileSystemObject to list the files.

Obviously, you need to replace "directoryname" with your directory name. Or better yet, if you know the physical path you can replace the virtual reference via Server.MapPath("/directoryname") with the actual path like this: "C:\Inetpub\wwwroot\homesite\directoryname"

Just make sure the directory has "read" permissions from the anonymous account or the IUSER_machinename account, or you will get a permission denied error.

Set MyDirectory=Server.CreateObject("Scripting.FileSystemObject")
Set MyFiles=MyDirectory.GetFolder(Server.MapPath("/directoryname"))
For each filefound in MyFiles.files

<% =filefound.Name & "<br>" %>

<% Next %>

A good idea would be to make this your default.asp page for each directory, then you could create custom links to files, instead of the default directory indexing page in IIS.


Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image