sroux has asked for the wisdom of the Perl Monks concerning the following question:

Dear guruz, As a Perl advanced beginner I'm looking for a module that could help in generating an HTML file "catalog" from a specified filesystem and or a specified file extension. The idea is to scan existing files in order to create a kind of catalog for further documentation (ie. file title, last update, content...). It smelt like this could be an easy thing to code but who knows maybe it already exists? The good thing would that the script provide HTML format (with CSS?) for a sexy output! Many thanks for any help or tip that you could provide! SebRoux

Replies are listed 'Best First'.
Re: Catalog generator
by Khen1950fx (Canon) on Feb 03, 2011 at 11:34 UTC
    HTML::Index::Document does exactly what you want.
    #!/usr/bin/perl use strict; use warnings; use HTML::Index:::Document; my $doc = HTML::Index::Document->new( path => $path ); $doc = HTML::Index::Document->new( name => $name, contents => $contents, mod_time => $mod_time, );
Re: Catalog generator
by marto (Cardinal) on Feb 03, 2011 at 10:45 UTC
Re: Catalog generator
by Corion (Patriarch) on Feb 03, 2011 at 11:44 UTC
Re: Catalog generator
by JavaFan (Canon) on Feb 03, 2011 at 10:39 UTC
    Seems like you want to do a find, a stat call for each file, and create an HTML table. All fairly simple.

    Is there anything specific you need help with?

Re: Catalog generator
by zentara (Cardinal) on Feb 03, 2011 at 15:10 UTC
    If you want a roll_your_own script. Here is a start. It will find all the images in a directory, make thumbnails, and setup a framed html page set for you.
    #!/usr/bin/perl use warnings; use strict; use Imager; use Cwd; use File::Basename; #but imager makes it easy opening different file types #watch the width of your picture names #they can widen the table cells if too long umask 0022; my $image = Imager->new(); my $count = 0; my $dir = cwd; my @exts = qw(.jpg .png .gif); # list allowed extensions my @pics= <*.jpg *.gif *.png>; open(HEADER,">header.html"); print HEADER<<End_Header; <html> <BODY Text="#99CCFF" BGCOLOR="#000000"> <center><h1>Thumbnails for $dir</h1></center> </body> </html> End_Header close HEADER; open(INDEX,">index.html"); print INDEX<<End_Index; <html> <head> <TITLE>Thumbnails</TITLE> <link rel="icon" href="favicon.ico"> </head> <frameset rows="70,*" border="0"> <frame name="header" src="header.html" marginwidth="0" marginheight=" +0" scrolling="off" frameborder="0"> <frameset cols="130,*" border="0"> <frame name="left" src="left.html" marginwidth="5" marginheight="5 +" scrolling="yes" frameborder="5"> <frame name="main" src="main.html" marginwidth="5" marginheight="5 +" scrolling="yes" frameborder="5"> </frameset> </frameset> </html> End_Index close INDEX; open(MAIN,">main.html"); print MAIN<<End_Main; <html> <BODY TEXT="#FFCCCC" BGCOLOR="#000000"> <center><h1>Click thumbnails at left to view</h1></center> </body> </html> End_Main close MAIN; open(OUT,">left.html"); print OUT<<End_Header; <html> <body> <table align=left bgcolor=9999CC border=2 cellpadding=2 cellspacing=2> <tr> End_Header foreach my $pic (@pics){ $count++; my ($basename,$path,$suffix) = fileparse($pic,@exts); $image->open(file=>$pic) or die $image->errstr(); # my $w = $image->getwidth(); # my $h = $image->getheight(); # Create smaller version my $thumb = $image->scale(xpixels=>100); #$basename.="-t$suffix"; #keeps same ext $basename.='-t.jpg'; #make all thumbs as jpg print "Storing image as: $basename\n"; $thumb->write(file=>$basename, jpegquality=>30) or die $thumb->e +rrstr; # my $tw = $thumb->getwidth(); # my $th = $thumb->getheight(); print OUT<<EOTR; <td align=center><a href="$pic" target=main alt="[$pic]"><img alt= [$p +ic-thumbnail] src=$basename ></a><br>$pic</td> EOTR if($count == 1){print OUT "</tr><tr>"; $count = 0}; } print OUT<<EOHTML; </tr> </table> </body> </html> EOHTML close OUT;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh