% OPTION EXPLICIT %>
<%
DirectoryFileListerStartUp()
RenderDirectoryFileListHTML()
'-------------------------------------------------------------------------------------------------------
const WORDS_TO_STRIP_FROM_PATH = ""
const FOLDER_DOESNT_EXIST = 0
const ACCEPTABLE_FILES_LIST = "pdf zip rar doc txt jpg gif"
Dim g_StrFullFilePath
Dim g_StrFileDir
Dim g_strAcceptableFileList
Dim g_StrArrFileNames
'-------------------------------------------------------------------------------------------------------
Function DirectoryFileListerStartUp()
g_strAcceptableFileList = ACCEPTABLE_FILES_LIST
GetFileDirPath()
GenerateFileList(g_StrFullFilePath)
End Function
'-------------------------------------------------------------------------------------------------------
Function RenderDirectoryFileListHTML()
%>
Directory File Lister
<% RenderHyperlinkFileList() %>
<%
End Function
'-------------------------------------------------------------------------------------------------------
Function RenderHyperlinkFileList()
Dim iCounter
For iCounter = 0 To UBound(g_StrArrFileNames)
response.write "" & g_StrArrFileNames(iCounter) & "
" & vbCrLf
Next
End Function
'-------------------------------------------------------------------------------------------------------
Function GenerateFileList(strInputDirPath)
'get list of files
Dim FileSysObj
Dim FolderObj
Dim tempObj
Dim strSelected
Dim iNumOfFiles
Dim iCounter
iCounter = 0
Set FileSysObj = Server.CreateObject("Scripting.FileSystemObject")
Set FolderObj = FileSysObj.GetFolder(strInputDirPath)
For Each tempObj In FolderObj.files
if (NOT InStr(LCase(g_strAcceptableFileList), LCase(Split(tempObj.Name, ".")(1) )) = 0) then
iNumOfFiles = iNumOfFiles + 1
end if
Next
ReDim g_StrArrFileNames(iNumOfFiles)
For Each tempObj In FolderObj.files
if (NOT InStr(LCase(g_strAcceptableFileList), LCase(Split(tempObj.Name, ".")(1) )) = 0) then
g_StrArrFileNames(iCounter) = tempObj.Name
iCounter = iCounter + 1
end if
Next
Set FolderObj = nothing
Set FileSysObj = nothing
End Function
'-------------------------------------------------------------------------------------------------------
Function GetFileDirPath()
Dim strServerVar
Dim iFolderExists
Dim strFilePath
Dim strRtnValue
strServerVar = Request.ServerVariables("PATH_TRANSLATED")
strFilePath = Left(strServerVar, (Len(strServerVar) - Len(GetPageName())))
strFilePath = StripWordsFromPath(strFilePath, WORDS_TO_STRIP_FROM_PATH)
g_StrFullFilePath = strFilePath & g_StrFileDir
'check if the folder actually exists
iFolderExists = DoesFolderExist(g_StrFullFilePath)
if (iFolderExists = FOLDER_DOESNT_EXIST) then
Response.Write "Error: file folder couldn't be found (" & g_StrFullFilePath & ")."
response.end
end if
End Function
'-------------------------------------------------------------------------------------------------------
Function Debug(strInputValue)
response.write "*" & strInputValue & "*
" & vbCrLf
End Function
'-------------------------------------------------------------------------------------------------------
Function GetPageName()
'get the name of the current page
Dim strTempPageName
strTempPageName = Split(Request.ServerVariables("SCRIPT_NAME"),"/")
GetPageName = strTempPageName(UBound(strTempPageName))
End Function
'-------------------------------------------------------------------------------------------------------
Function DoesFolderExist(strInputFolderPath)
Dim iRtnValue
Dim objFileSystem
Set objFileSystem = Server.CreateObject("Scripting.FileSystemObject")
if (objFileSystem.FolderExists(strInputFolderPath) = true) then
iRtnValue = 1
else
iRtnValue = 0
end If
Set objFileSystem = Nothing
DoesFolderExist = iRtnValue
End Function
'-------------------------------------------------------------------------------------------------------
Function StripWordsFromPath(strInputPath, strInputWordsToStrip)
Dim strRtnValue
Dim strArrWordsToStripFromPath
Dim iCounter
Dim strWordToStrip
strArrWordsToStripFromPath = Split(strInputWordsToStrip, ",")
'adjust the path so certain directories are stripped out.
For iCounter = 0 To UBound(strArrWordsToStripFromPath)
strWordToStrip = Trim(strArrWordsToStripFromPath(iCounter))
strInputPath = Replace(strInputPath, strWordToStrip, "")
Next
'correct for any strange path characters
strRtnValue = Replace(strInputPath, "\\", "\")
StripWordsFromPath = strRtnValue
End Function
'-------------------------------------------------------------------------------------------------------
%>