[Memphis.pm] Re: [GOLUM] How do I...?

Brock Sides philarete at mindspring.com
Sun Jun 17 17:27:55 CDT 2001


* jlboers <jlboers at localhost.localdomain> [010617 17:05]:

> I want to make a index file called index.html
> I have a directory full of pictures in various formats, but mostly jpeg.
> i want to make a cd with all the pictures, but want to be able to browse them 
> via this index.html file. 
> 
> i know that there is a way this can be scripted to read a directory's 
> contents and output it to a text file.
> 
> Does anyone have an idea on how to do this? 

TMTOWTDI, of course. Here's a way to do it in bash:

#!/bin/bash

cat >index.html <<FIN
<html>
<body bgcolor=white>
<h1>My Pictures</h1>
FIN

for i in *.jpg *.png *.gif ; do
   echo "<a href=$i>$i</a><br>" >>index.html
done

cat >>index.html <<FIN
</body>
</html>
FIN

And here's one way to do it in perl:

#!/usr/bin/perl -w

open(FH, ">index.html") or die $!;

print FH <<FIN;
<html>
<body bgcolor=white>
<h1>My Pictures</h1>
FIN

opendir(DH, '.') or die $!;

while ($_ = readdir DH) {
   if (m/\.jpg/ or m/\.png/ or m/\.gif/) {
      print FH "<a href=$_>$_</a><br>\n";
   }
}

print FH <<FIN;
</body>
</html>
FIN

__END__

Adjust the html to suit your needs.

-- 
Brock Sides
philarete at mindspring.com

One OS to rule them all, one OS to find them,
One OS to bring them all and in the darkness bind them,
In the land of Redmond, where the shadows lie.
----------------------------------------------------------------------------
To unsubscribe, please send email to majordomo at pm.org
with 'unsubscribe memphis-pm-list' in the body of the message.
----------------------------------------------------------------------------




More information about the Memphis-pm mailing list