0

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. http://coffeescripter.com/code/ad-gallery/

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!

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by Tofudisan
0

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. http://coffeescripter.com/code/ad-gallery/

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.

Edited by Tofudisan: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.