asp/dhtml Image Preloader

Source: Internet
Author: User
Tags array
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



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.