Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with getting data from folders

Status
Not open for further replies.

gibbo171

Programmer
Dec 13, 2007
33
GB
Hi All

First post here so please be patient with me, I have a slide show using the code below,

This is great but what i need to do is instead of specifying the image names in the boy of my html page I need to point at a folder on my intranet server and run through each file in that folder (All images) and display them one after the other as my slide show,

can this be done?

can someone point me in the right direction please

thanks

Gibbo


<HEAD>

<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ricocheting (ricocheting@hotmail.com) -->
<!-- Web Site: -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->

<!-- Begin
var rotate_delay = 5000; // delay in milliseconds (5000 = 5 secs)
current = 0;
function next() {
if (document.slideform.slide[current+1]) {
document.images.show.src = document.slideform.slide[current+1].value;
document.slideform.slide.selectedIndex = ++current;
}
else first();
}
function previous() {
if (current-1 >= 0) {
document.images.show.src = document.slideform.slide[current-1].value;
document.slideform.slide.selectedIndex = --current;
}
else last();
}
function first() {
current = 0;
document.images.show.src = document.slideform.slide[0].value;
document.slideform.slide.selectedIndex = 0;
}
function last() {
current = document.slideform.slide.length-1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
}
function ap(text) {
document.slideform.slidebutton.value = (text == "Stop") ? "Start" : "Stop";
rotate();
}
function change() {
current = document.slideform.slide.selectedIndex;
document.images.show.src = document.slideform.slide[current].value;
}
function rotate() {
if (document.slideform.slidebutton.value == "Stop") {
current = (current == document.slideform.slide.length-1) ? 0 : current+1;
document.images.show.src = document.slideform.slide[current].value;
document.slideform.slide.selectedIndex = current;
window.setTimeout("rotate()", rotate_delay);
}
}
// End -->
</script>
</HEAD>
<BODY>

<center>
<form name=slideform>
<table cellspacing=1 cellpadding=4 bgcolor="#000000">
<tr>
<td align=center bgcolor="white">
<b>Image Slideshow</b>
</td>
</tr>
<tr>
<td align=center bgcolor="white" width=400 height=300>
<img src="cart.gif" name="show">
</td>
</tr>
<tr>
<td align=center bgcolor="#C0C0C0">
<select name="slide" onChange="change();">
<option value="cart.gif" selected>Cart
<option value="aat.gif">AAT
<option value="boat.gif">Boat
<option value="enterprise.gif">Enterprise
<option value="ewing.gif">E-Wing
<option value="f18.gif">F-18
<option value="klingon.gif">Klingon
<option value="landingcraft.gif">Landing Craft
<option value="hoverracer.gif">Hover Racer
<option value="sith.gif">Sith
</select>
</td>
</tr>
<tr>
<td align=center bgcolor="#C0C0C0">
<input type=button onClick="first();" value="|<<" title="Beginning">
<input type=button onClick="previous();" value="<<" title="Previous">
<input type=button name="slidebutton" onClick="ap(this.value);" value="Start" title="AutoPlay">
<input type=button onClick="next();" value=">>" title="Next">
<input type=button onClick="last();" value=">>|" title="End">
</td>
</tr>
</table>
</form>
</center>

<p><center>
<font face="arial, helvetica" size="-2">Free JavaScripts provided<br>
by <a href=" JavaScript Source</a></font>
</center><p>
 
I should also add that this is an internal intranet where my users will have access to read from the folder where the images are stored from their local machine over our network

thanks

gibbo
 
You will not be able to do this cross-browser without using some sort of server-side scripting. If you have a web server that supports something like ASP, JSP, PHP, etc, then you should use that to deliver an array of filenames to the page and iterate over them.

You could also fire off an AJAX request to get the filenames back, but you'd still need some sort of server-side scripting.

Of course, if your users are restricted to a single web browser, you might be able to get away without server-side scripting, but it's not as nice an approach.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan

thanks for the reply

I hoped because the slideshow is stored on an internal network with the image files in the same folder as the html file I would be able to do this, (Probably didnt explain myself very well actually), is it possible as this is the case with javascript then or if not what about a vbscript file that can run from the browser to pass the array of filenames over?

thanks

gibbo
 
Again, it depends if you need it to be cross-browser or not.

It also depends if the images have a common naming scheme, such as "Image001", "Image002", or whether they have arbitrary names.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan, thanks for the reply

No idea what you mean by cross browser, we only use Internet explorer in my company, i can have img1.jpg and so on if thats easier but would prefer not to if possible

thanks again

gibbo
 
No idea what you mean by cross browser

It means that the code would work in more than one browser, i.e. IE and Firefox. In your case, you've said this doesn't matter, so your options are increased.

If you still don't care for the server-side solution (which I still think is best), then because your users are running IE only, I'd investigate the FileSystemObject ActiveX control. It gives you the ability to get a list of files in any folder (local or network).

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
thanks Dan, thats really helpful and does give me a good starting point

I can definatly loop throught the folders using VB Script and put the file names in an array within my client html page but how do i then pass that into the javascript

Thanks again for taking so much time on helping me with this

Gibbo
 
You don't need VBScript at all - You can use JavaScript to access the FileSYstemObject. There should be many examples on the web, some in the FAQ section here, and certainly all the docs you'll ever need over at MSDN.

Shout if you get stuck!

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Dan

Im still really strugling with this

I found the following code to loop through my files


<script type="text/javascript">

// Reference the FileSystemObject
var FSO = Server.CreateObject("Scripting.FileSystemObject");

// Reference the Text directory
var Folder = FSO.GetFolder("./images/test");

// Reference the File collection of the directory
var FileCollection = Folder.Files;

Response.Write("JScript Method<BR>");

// Display the number of files within the Text directory
Response.Write("Number of files found: " + FileCollection.Count + "<BR>");

// Traverse through the FileCollection using the FOR loop
for(var objEnum = new Enumerator(FileCollection); !objEnum.atEnd(); objEnum.moveNext()) {
strFileName = objEnum.item();
Response.Write(strFileName + "<BR>");
}

// Destroy and de-reference enumerator object
delete objEnum;
objEnum = null;

// De-reference FileCollection and Folder object
FileCollection = null;
Folder = null;

// Destroy and de-reference FileSystemObject
delete FSO;
FSO = null;

</script>


but still cant figure out how to include this in my original code,

Would appreciate a bit more help with combining the two

thanks



Gibbo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top