473,468 Members | 1,314 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Displaying files in a folder

5 New Member
I'm new to Javascript and want to write a script which will loop through the files in a folder and display them in a webpage. I've written the following which alternately displays two images in a folder, but I want to be able to add new files to that folder and have them added to this loop. I'm assuming I just need some code to populate the list of files in the folder, but don't know how to do that, nor how to make var have a variable max depending on the number of files. This will all be displayed locally, so there's no kind of web server.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3.     <head>
  4.  
  5.         <title>CMM Reference Part Check Compliance</Title>
  6.  
  7.         <script type="text/javascript">
  8.             <!--
  9.             var image1=new Image()
  10.             image1.src="Slide1.gif"
  11.             var image2=new Image()
  12.             image2.src="Slide2.gif"
  13.             //-->
  14.         </script>
  15.  
  16.     </head>
  17.  
  18.     <body>
  19.  
  20.         <img src="Slide1.gif" name="slide" width="95%" height="95%" />
  21.  
  22.         <script>
  23.             <!--
  24.                 //variable that will increment through the images
  25.                 var step=1
  26.  
  27.                 function slideit() {
  28.                     //if browser does not support the image object, exit.
  29.                     if (!document.images)
  30.                         return
  31.                     document.images.slide.src=eval("image"+step+".src")
  32.                     if (step<2)
  33.                         step++
  34.                     else
  35.                         step=1
  36.                     //call function "slideit()" every 10 seconds
  37.                     setTimeout("slideit()",1000)
  38.                 }
  39.  
  40.                 slideit()
  41.             //-->
  42.         </script>
  43.  
  44.     </body>
  45.  
  46. </html>
How might I do this?

Thanks very much for your help
Jul 29 '09 #1
5 9407
Dormilich
8,658 Recognized Expert Moderator Expert
I don't think that javascript can read a directory, but if you name the files consistently you can request each of it with a loop.
Jul 29 '09 #2
Ca1icoJack
5 New Member
Thats part of the issue, the names won't be consistent since they'll be related to all sorts of different things. What would I use instead then? PHP was mentioned somewhere but I know absolutely nothing about that.
Jul 29 '09 #3
Canabeez
126 New Member
Here,

put this code in images.php, and place the file in your images directory.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.     header("Content-Type: text/javascript");
  3.     $AllowedExtensions = array(".gif", ".jpg", ".png", "jpeg");
  4.     echo "var images = new Array();";
  5.     $d = dir("./");
  6.     while (false !== ($entry = $d->read()))
  7.     {
  8.         if($entry != '.' && $entry != '..' && is_file($entry) && in_array(substr($entry,-4), $AllowedExtensions))
  9.         {
  10.             echo "images.push('{$entry}');";
  11.         }
  12.     }
  13.     $d->close();
  14. ?>
Then just call this file within <SCRIPT>
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" src="images/images.php"></script>
Jul 29 '09 #4
Ca1icoJack
5 New Member
Thanks very much, but how do I use that in the HTML? Where do I set the time delay between updating etc? (I'm new to all of this)
Jul 29 '09 #5
Dormilich
8,658 Recognized Expert Moderator Expert
@Ca1icoJack
just call the script (as Canabeez posted)

@Ca1icoJack
that's a question how you set the cache instructions. probably
Expand|Select|Wrap|Line Numbers
  1. // in images.php
  2. header('Cache-Control: must-revalidate');
could suffice (more Cache-Control options). Cache instructions may also be set by the server.
Jul 30 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: D Wright | last post by:
It would suffice to state, I am very new to the .NET world, as well as to Visual Studio, Visual C#, and ASP.NET. Nonetheless, I'm certain the solution to several challenges I've presented myself...
15
by: Jameson | last post by:
Happy New Year, Everyone! I am trying to figure out how to display a bunch of images (mainly JPEGs, but possibly a few GIFs and PNGs as well) that are stored in a local directory on the system....
4
by: KitKat | last post by:
Problem trying to figure this out, using a combo box selection I need to go to each folder, Cam 1, Cam 2, Cam 4, Cam 6, Cam 7,and Cam 8 and display each picture (from selection) from each folder...
1
by: mmalinsky | last post by:
I have the following code that I borrowed from this NG to copy files from one location to another: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
2
by: Mark Rae | last post by:
Hi, Just looking for some advice and/or recommendations here. Scenario is corporate private intranet, ASP.NET 2 on Win2K3S, SQL Server 2005, WinXP + IE6 on all client desktops. Client has a...
12
by: lord.zoltar | last post by:
Hello, I have a help file as a chm, which is added to the project as a resource. I'm trying to display it as System.Windows.Forms.Help.ShowHelp(Me, "Name_Of_Helpfile_Resource") which obviously...
8
by: Lloyd Sheen | last post by:
I have a list of JPG's which are found in a SQL Server database. When the page selects a certain piece of data it will refer to the file system (resident on IIS server with a virtual directory)...
1
by: =?Utf-8?B?UmljaA==?= | last post by:
I removed a form and all its associated files (designer, vb, resx) from a project because I was having a problem with that form. I copied these files to another folder away from the project...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.