100% client side - Trying to produce a table of images using HTML document on CD.

P

Phrederik

Hi!

Apologies for this post... This post isn't 100% on topic, but the scripting
groups I have access to don't seem to move much...

I'm trying to piece together a small bit of code for my folks. They have a
bunch
of pictures that they are trying to organize for the family by buring to CD
and using an HTML page for browsing.

What they want is the ability to create a list of filenames for images. When
the page opens, some script will read the file and build a table of those
images. Along with each image, it should also include the contents of a file
with the same name as the image, but with a TXT extension on the filename.
(ie. If the list file had "picture1.jpg" for an entry, that image would
appear in one of the table cells along with the contents of "picture1.txt".)

Myself, I'm fairly new to scripting and web programming in general. I've
pasted my current code below. It's definately not 100% yet.

My real problem right now is that you cannot count on the drive letter of
the CDRom drive being the same. When I run my page, I do not know where the
FSO is trying to find my documents. I need to use a relative path with the
FileSystem Object. What is the root that it uses? Is there a way I can
reference the root of the HTML document currently being shown/parsed? ALL
files will reside within the same folder(HTML, list, images and TXT
descriptions.)

I'd also be interested in any other comments about my code.

My code (excuse the wrapping):

<html>
<head>
<title>Web Page Title</title>
</head>
<body>
<script language="JavaScript">
//Script runs at this point of page. Reads input file and builds table
based on contents.
//First line of file is Page title
//Rest of lines are filenames of images. Text description is taken from
filename, using TXT for file extension.

var i=0; //Image counter

var columns = 3; //How many columns wide?
var max=100; //Maximum number of pictures to show
var columnCount=0; //Counts the currently displayed column
var inFile = "list.txt"; //Name of file to read

var inLine; //Holds the current line read from the file
var inText; //Used to hold filename of text description

var READ =1; //Means "READ ONLY" for the filesystem
object
var fso = new ActiveXObject("Scripting.FileSystemObject"); //This object
is used to access the file system

// *** MAIN PROBLEM HERE - HOW DO A SPECIFY A RELATIVE PATH TO THIS HTML
DOCUMENT??? ***
var file = fso_OpenTextFile( inFile,READ); //Create a file object
from the file system object, used to read the file list

//Display title
inLine= file.ReadLine(); //Get first line of file for page title
document.writeln ("<center><h1>" + inLine + "</h1></center><hr>");

//Start table
document.writeln ("<table bgcolor='F0E0FF'>");

//Loop through file until we get to the end of the file
while ((! file.AtEndOfStream) && i < max) {
i++; //Counter to make sure we don't go past "max" number of pictures.
//If column counter is 0, we need to start a row
if (columnCount == 0) { document.writeln (" <tr>"); }
//Read a line in
inLine = file.ReadLine(); //Get a line from the file
//*** AT THIS POINT WE NEED TO STRIP EXTENTION FROM FILENAME
// AND ADD ".TXT" TO GET DESCRIPTION FILENAME. THEN GET FILE
// CONTENTS TO ADD TO TABLE CELL ***
//Build the table cell
document.writeln (" <td align='center' valign='middle'><img src='" +
inLine +"'><br>Dummy description text.</td>");
//If we've put enough pictures for one row, end the row and reset the
column counter
columnCount++; //Add one to column count
if (columnCount == columns) {
columnCount = 0;
document.writeln (" </tr>");
}
}
fso.close; //Close the filesystem object
document.writeln ("</table>");
</script>
</body>
</html>


Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top