Q&A: Can you help with Java or other Scripting?

photo selling script
by wallyg

Question by Marvinator: Can you help with Java or other Scripting?
I’m pretty good with standard HTML (very very basic stuff) but would like to create a page of photos for my wife to display her jewelry. Coding using ‘img src’ will actually give me more work as each item will be unique and once it’s sold, the photo removed.

What I’d like to see is a java script (or other scripting?) which would take a folder of pictures and display them, making each a thumbnail , say, 4 across, (clickable thumb to display a larger photo). In this manner, all she’d have to do is delete the photo from the folder and it’s gone from the webpage.

Can this be done easily?

Best answer:

Answer by bohabohu
JavaScript is probably not your language of choice for this since JavaScript can’t read a list of files in a folder. Without learning full server-side scripting, you could run a quick python script or something to generate the HTML page on your computer and then upload it.

Download and install python (python.org)
Create a new file called anything.py in the same folder as all the pictures on your computer with the following code in it:

import os
files = os.listdir(‘.’)
c = open(‘page.html’, ‘wt’);
c.write(
“””
This is where you would put the html above the list of pictures

“””)
while len(files) > 0:
\t c.write(‘

‘)
\t files = files[4:]
c.write(“””

‘ + ‘ ‘.join(files[:4]) + ‘

This is where you put the html below the list of pictures

“””)
c.close()

Y! Answers doesn’t seem to allow me to post whitespace at the beginning of the line, so “\t” means tab

Know better? Leave your own answer in the comments!

Get the book now