[script language = "jscript" runat = "server"] /*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--* * FUNCTION: fnFileIndex() * DESCRIPTION: This function creates a list of files (optionally filtered by a 'FileNamePattern') from a listing of a directory on the server computer. * WORKING HISTORY: 12th Dec 2000-- coded from notes. * DOCUMENTED AT: http://www.geocities.com/matth3wbishop/eg/asp/ * CODE LOCATION: http://www.geocities.com/matth3wbishop/eg/asp/ * DEPENDENCIES: fnErrorMessage * STATUS: in dev * NOTES: Maybe there should be an 'Ordinal type' parameter sFolderPath, //--The path to the directory sFileNamePattern, //--A filter for the files sRelativeUrl, //--Relative location from the 'client' page sListTitle, //--The heading to appear above the list (?) sBgcolour, //--The background Colour for the file list sFontColour) //--The foreground (text) colour for the list. *--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*/ function fnFileIndex( sFolderPath, sFileNamePattern, sRelativeUrl, sListTitle, sBgcolour, sFontColour) { var fsoFileSystem; //-- var dirFolder; //--Directory object var collFiles; //--Collection of files var ss; //-- var ii; //--Loop counter var sReturn; //--The function output var rxFileNamePattern; //--Regular expression filter var sCurrentFile; //--Looped file fsoFileSystem = Server.CreateObject("Scripting.FileSystemObject"); if (sFolderPath == null) { sFolderPath = "."; } if (sFileNamePattern == null) { sFileNamePattern == ""; } if (sRelativeUrl == null) { sRelativeUrl = ""; } if (sBgcolour == null) { sBgcolour = "lightblue"; } if (sFontColour == null) { sFontColour = "blue"; } eval("rxFileNamePattern = /" + sFileNamePattern + "/gi;"); //--rxFileNamePattern = /\.dll/gi; //--Response.Write(rxFileNamePattern.source); //--Response.End(); if (!fsoFileSystem.FolderExists(sFolderPath)) { fnErrorMessage( "fnFileIndex", "sFolderPath (" + sFolderPath + ")", "The specified folder does not exist"); } /* if */ dirFolder = fsoFileSystem.GetFolder(sFolderPath); collFiles = new Enumerator(dirFolder.Files); sReturn = "<table border = '0' \n" + " cellpadding = '1' \n" + " cellspacing = '1'> \n"; if (sListTitle != null) { sReturn += "<tr> \n" + " <td bgcolor = \"" + sBgcolour + "\"> \n" + " <font size = \"+1\" \n" + " color = \"" + sFontColour + "\"> \n" + Server.HTMLEncode(sListTitle) + "</font></td> \n" + "</tr> \n"; } /* if */ ii = 1; for (; !collFiles.atEnd(); collFiles.moveNext()) { sCurrentFile = collFiles.item().Name; //Response.Write(sCurrentFile); if (rxFileNamePattern.test(sCurrentFile) == true) { sReturn += "<tr> \n" + " <td bgcolor = \"" + sBgcolour + "\"> \n" + " <font size = \"+0\" \n" + " color = \"" + sFontColour + "\"> \n" + " <a href = \"" + sRelativeUrl + sCurrentFile + "\"> " + Server.HTMLEncode(sCurrentFile) + "</a></font> \n" + " </td> \n" + "</tr> \n"; ii++; } /* if */ } /* for */ sReturn += "</table>"; return sReturn; } /* fnFileIndex */ [/script]