...

View Full Version : list and link files



scroots
07-15-2002, 09:29 PM
how would i using ASP be able to list files in a directory on a server (the folders location is in a textbox) and then have ASP list and link all the files in that folder.

thanks in advance

scroots

Roelf
07-18-2002, 07:22 AM
<%@ LANGUAGE="JSCRIPT" %>
<%
var directory = "" + Request.Form("directory");
if (directory == "undefined"){
directory = "";
}
%>
<html>
<head><title>List and link</title></head>
<form method="POST" action="<%=Request.ServerVariables("SCRIPT_NAME")%>">
<table>
<tr>
<td>
Directory:
<input name="directory" type="TEXT" value="<% = directory %>" size="50">
</td>
<td>
<input type="SUBMIT" value="Open">
</td>
</tr>
</table>
</form>

<%
if (directory != ""){
var fileobject = Server.CreateObject("Scripting.FileSystemObject");
if ( fileobject.FolderExists(directory)){
var folder = fileobject.GetFolder(directory);
var filelist = new Enumerator(folder.Files);

for ( filelist.moveFirst() ; !filelist.atEnd() ; filelist.moveNext()) {
var file = filelist.item();
Response.write ("<a href='" + file.Path + "'>" + file.Name + "</a><br>\n");
}
}
}
%>
</body>
</html>

put this in a file, like list.asp. put the file in a folder under your website. open it, fill in a directory, click open and voila

scroots
07-18-2002, 06:09 PM
Thank you so much it will save me lots of time hand coding it all.

scroots



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum