Hello all. It's my first forum post on DaniWeb. Hope to meet like-minded people here : )

I have installed a JQuery Photo Gallery: pretty nifty one.

I was planning to have a folder in my web directory called "Photographs", containing both photographs and thumbnails of the photographs for the Photo Gallery.

Is there a method where I will be able to get a list of the File Names of the files in the folder "Photographs", and store each of the filename in an Array? I don't want to have to hardcode one photo one at a time: it'll be convenient if I'll need to add in new photographs in the future.

The following are the hierarchy of the file/folder.

sichuan/index.asp - File containing the script
sichuan/photographs/ - Folder containing the photographs
sichuan/photographs/thumb - Folder containing the thumbnails of the photographs

I understand that I should be able to use some of these file system objects, but I'm not sure how to... http://www.w3schools.com/asp/asp_ref_filesystem.asp'

Any suggestions? Thanks!

Dani AI

Generated

Good start, ’s server-side approach is the right direction. For a cleaner integration with your jQuery gallery, expose the photo filenames from the server as a small JSON endpoint that the client can fetch. The standard Classic ASP tool for enumerating files is the Scripting.FileSystemObject. (learn.microsoft.com)

Example: create /sichuan/photographs/list.asp that returns a JSON array of filenames. This keeps the page HTML small and lets the gallery request the list asynchronously.

<%
Response.ContentType = "application/json"
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder(Server.MapPath("/sichuan/photographs/"))

Dim files(), c
c = -1
For Each f In fld.Files
  ext = LCase(Right(f.Name,4))
  If ext = ".jpg" Or ext = ".png" Or ext = ".gif" Or LCase(Right(f.Name,5)) = ".jpeg" Then
    c = c + 1
    ReDim Preserve files(c)
    files(c) = f.Name
  End If
Next

If c = -1 Then
  Response.Write "[]"
Else
  Response.Write "["
  For i = 0 To UBound(files)
    s = files(i)
    s = Replace(s, "\", "\\")
    s = Replace(s, Chr(34), "\u0022")
    Response.Write """" & s & """"
    If i < UBound(files) Then Response.Write ","
  Next
  Response.Write "]"
End If

Set fld = Nothing
Set fso = Nothing
%>

Client side (jQuery): fetch that endpoint and build the gallery when the list arrives (e.g., $.getJSON('/sichuan/photographs/list.asp', function(files){ ... })). Use Server.MapPath on the server to translate the virtual path to a physical path when enumerating. (learn.microsoft.com)

Pairing thumbs and sorting: check for a thumbnail file in /photographs/thumb/ using fso.FileExists(Server.MapPath("/sichuan/photographs/thumb/" & fname)) and fall back if missing. If you want files ordered by date, the File object exposes DateLastModified/DateCreated. (learn.microsoft.com)

Cautions: ensure the IIS application‑pool identity has read/list access to the photographs folder (permission errors like 800A0046 mean an ACL problem). (learn.microsoft.com) For better performance, cache the generated list in the Application object and use Application.Lock/Unlock carefully (holding locks too long can cause timeouts). (learn.microsoft.com)

This keeps the gallery dynamic, avoids hardcoding filenames, and keeps the client-side code simple while addressing permissions, ordering, and performance.

Hello all. It's my first forum post on DaniWeb. Hope to meet like-minded people here : )

I have installed a JQuery Photo Gallery: pretty nifty one.

I was planning to have a folder in my web directory called "Photographs", containing both photographs and thumbnails of the photographs for the Photo Gallery.

Is there a method where I will be able to get a list of the File Names of the files in the folder "Photographs", and store each of the filename in an Array? I don't want to have to hardcode one photo one at a time: it'll be convenient if I'll need to add in new photographs in the future.

The following are the hierarchy of the file/folder.

sichuan/index.asp - File containing the script
sichuan/photographs/ - Folder containing the photographs
sichuan/photographs/thumb - Folder containing the thumbnails of the photographs

I understand that I should be able to use some of these file system objects, but I'm not sure how to... http://www.w3schools.com/asp/asp_ref_filesystem.asp'

Any suggestions? Thanks!

Here's one way:

'get the FileSystemObject object
set FSO = Server.CreateObject("Scripting.FileSystemObject")
'use the FSO to get the folder you want
Set PicsFolder = FSO.GetFolder(Server.MapPath("/sichuan/photographs/"))
Set ThumbsFolder = FSO.GetFolder(Server.MapPath("/sichuan/photographs/thumb/"))

'the PicsFolder.Files & ThumbsFolder.Files collections can 
'be loaded into arrays (and basically are arrays anyway)
'Examle:

For each i In PicsFolder.Files
  PicArray = PicArray & i.Name & "|"
Next
PicArray = left(PicArray,len(PicArray)-1) 'trims off the trailing "|" 
PicArray = split(PicArray,"|") 'create the array

'Do the same thing with ThumbsFolder

set FSO = nothing
set PicsFolder = nothing
set ThumbsFolder = nothing

Note that this all occurs server side before the page is served to the browser. So your jQuery interface won't really have access to the array. One way around this is to not split PicArray and instead write that out as a string in the javascript variable assignment:

<%
'get the FileSystemObject object
set FSO = Server.CreateObject("Scripting.FileSystemObject")
'use the FSO to get the folder you want
Set PicsFolder = FSO.GetFolder(Server.MapPath("/sichuan/photographs/"))

For each i In PicsFolder.Files
  PicArray = PicArray & i.Name & ","
Next

set FSO = nothing
set PicsFolder = nothing
%>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
  var PicArray = <%=PicArray%>;    
/*]]>*/
</script>

The above example will parse the files in the folder when generating the page and then basically "hard-code" the comma-delimited string into the javascript global variable declaration. From there you can use javascript to split the variable into an array usable by your jQuery photo album script.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.