CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   ASP (http://www.codingforums.com/forumdisplay.php?f=8)
-   -   list and link files (http://www.codingforums.com/showthread.php?t=2051)

scroots 07-15-2002 09:29 PM

list and link files
 
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


All times are GMT +1. The time now is 07:30 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.