|
ASP Code to put files in directory into select/option form object Posted: 4 Feb 2004
Sorry about the format - i'm limited to 4000 chars and this function is actually larger than that - but it'll give you the concept. ------------ code until end of post -------------- <!--#include virtual="/new/common/utils/qsort.asp" --> <% ' ' DirFilestoOptions(DirName, SortOrder) ' DirName = name of relative path from curent file to generate options from ' SortOrder = True (ascending), False (descending) ' ' This subroutine takes a relative path spec., gets a list of files from it, sorts the ' list of files, and then outputs options as part of a <select> tag in a form. ' The option value=<x> will be set to point to the relative URL for the files. ' All date related names will be translated to Month and Year for display purposes ' if filelimit is specified, the files will be limited ' sub DirFilestoOptions(DirName, FileLimit, LimitCompare, SortOrder) dim FileSysObj, DirObj, fname, flink, tmp, fpath, fileobj, pos, npos, skipfile, iStart, iEnd, iStep set FileSysObj=Server.CreateObject("Scripting.FileSystemObject") fpath=server.MapPath(DirName) set DirObj = FileSysObj.GetFolder(fpath) if (isempty(DirObj)) then response.write("<option value=""#"">Internal File Structure Error</option>") else dim I I = DirObj.files.count dim filelist() redim filelist(I) I=1 for each fileobj in DirObj.files filelist(I) = fileobj.name I=I+1 next %> <script language="VB"> QSort(filelist, 1, DirObj.files.count) </script> <% if SortOrder then iStart = 1 iEnd = DirObj.files.count iStep = 1 else istart = DirObj.files.count iend = 1 iStep = -1 end if for I = iStart to iEnd step iStep fname=lcase(filelist(I)) flink= DirName & "/" & fname response.write("<option value=""" & flink & """>" & fname & "</option>") next end if end sub %>
|