DHTML Tutorials & Code Snips:graphics & charts:images\\
This ASP Script recurses through a directory tree and loads images into a DHTML preloader.
The Asylum for letting me with his DHTML site Preloader. This
Version would be even less work, because all are tell the ASP to drill down through a directory
Structure looking for images, and it'll place all the "image names into" array, and off it goes.
The setup for this is incredibly simple. The following variables of the preloader.asp, open, and change:
-Boolrecurse:tell the script to drill down through subdirectories within the folder for you choose
(True/false)
-Strvirtualroot:the folder that contains all the images
<%
Boolrecurse = True ' recurse through subdirectories? True/false
Strvirtualroot = ".. /.. /images "' Directory
Strrootfolder = Server.MapPath (strvirtualroot) ' Grab directory
IntSize = 0
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
Set objfolder = Objfso.getfolder (Strrootfolder)
Stroutput = Traversefolder (objfolder, Strvirtualroot, Boolrecurse)
Stroutput = Mid (Stroutput, 1, Len (stroutput)-2)
Set objFSO = Nothing
Set objfolder = Nothing
Function Traversefolder (objfolder, Strvirtualroot, Boolrecurse)
Stroutput = ""
Arrimages = Array ("gif", "JPG", "PNG", "JPEG")
' Only process directories ' don't start with
' An underscore.
If not left (objfolder.name, 1) = "_" Then
Dim objfile, strpath, strFileName, Strfilesize, strextension
' Iterate through each file in the folder
For each objfile in Objfolder.files
' Obtain the extension of the current file
strpath = Objfile.path
strFileName = Objfile.name
Intfilesize = Objfile.size
strextension = Ucase (Right (strpath, Len (strpath)-InStrRev (strpath, "."))
' If ' is ' a image
For x = LBound (arrimages) to UBound (arrimages)
If strextension = Ucase (arrimages (x)) then
Stroutput = stroutput & "' & Strvirtualroot &"/"& strFileName &" ', "
IntSize = intSize + intfilesize
End If
Next
Next
If Boolrecurse Then
' Recurse through the folder ' s subdirectories
For each objsubfolder in Objfolder.subfolders
Stroutput = stroutput & Traversefolder (Objsubfolder, Strvirtualroot & "/" &
Objsubfolder.name, Boolrecurse)
Next
End If
Traverse