RSS Element,demiblog Class,Language,Link,Title,Description channel,,en_GB,http://tobyinkster.co.uk/article/source2html/,source2html,"
I needed to print out a directory full of small scripts. This Perl script will go through the current directory and create a pretty HTML page of all the files in that directory. That HTML page can then be fed to a browser for printing.
#!/usr/bin/perl $cd = `pwd`; chomp $cd; $ls = `ls -1 $cd`; @ls = split(/\n/,$ls); print ""<title>Directory Listing $cd</title>\n""; print ""<h1>Directory Listing $cd</h1>\n""; $ll = `ls -l '$cd'`; chomp $ll; print ""<pre style='padding:1em'><b>$ll</b></pre>\n\n""; foreach $f (@ls) { if (!(-d $f)) { $l = `ls -l '$f'`; chomp $l; print ""<div style='border:2px solid black;padding:1em;'>\n""; print ""<h2 style='margin:0;padding:0;'>$f</h2>\n""; print ""<pre><b>$l</b></pre>\n""; print ""</div>\n""; $t = `cat '$f'`; $t =~ s/&/&/g; $t =~ s/</</g; $t =~ s/>/>/g; print ""<pre style='padding:1em'>$t</pre>\n\n""; } } This software is distributed under the terms of the GNU GPL.
"