<%/* ============================================================================= Files.asp VERSIONINFO Version: __PUT_PHAROS_VERSION_HERE__ Copyright: Copyright © 2005 Pharos Systems Inc Description: This file contains functions used for performing file system operations such as listing the files within a directory. Notes: Warning: This software is property of Pharos Systems New Zealand Ltd. Unauthorized use or duplication of this software is strictly prohibited. Authorized users are subject to the following restrictions: * Neither the author, their corporation, nor Pharos Systems New Zealand Ltd. is responsible for any consequences of the use of this software. * The origin of this software must not be misrepresented either by explicit claim or by omission. * Altered versions of this software must be plainly marked as such. * This notice may not be removed or altered. ================================================================================ */%> <% // Returns an array of the files in the given relative directory on the server that // match the regular expression matchRegex (if specified) and do not match the // regular expression doNotMatchRegex (if specified). // The names of the returned files are relative to the server root path. function GetFileList( directory, matchRegex, doNotMatchRegex ) { var fileSystemObject = Server.CreateObject( "Scripting.FileSystemObject" ); var serverDir = Server.MapPath( directory ); if ( !fileSystemObject.FolderExists( serverDir ) ) { throw new Error( "The directory '" + directory + "' does not exist." ); } var files = new Enumerator( fileSystemObject.GetFolder( serverDir ).Files ); var matchingFiles = new Array(); for ( ; !files.atEnd(); files.moveNext() ) { var file = files.item(); if ( null != matchRegex && file.name.match( matchRegex ) && ( null == doNotMatchRegex || !file.name.match( doNotMatchRegex ) ) ) { matchingFiles[ matchingFiles.length ] = RemoveTrailingPathChar( directory ) + "/" + file.name; } } return matchingFiles; } // Removes any trailing path characters from the given path. function RemoveTrailingPathChar( path ) { return path.replace( /[/\\]+$/, "" ); } %>