-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Anyone have a good script to generate an HTML file for a directory listing?
- -James Kosin
James Kosin wrote:
Anyone have a good script to generate an HTML file for a directory listing?
In what language?
Here are some pieces that can get you going. You can also do this is sh, perl, etc., with a simple loop[1].
python: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/200131
php: <?php $dir = opendir("."); while ($file = readdir($dir)) { if ($file != "." && $file != ".." && $file != "") { if (is_dir($file)){ print "<li><a href=\"$file/\">$file</a></li>\n"; } } } closedir($dir); clearstatcache(); ?> Not tested. [1]http://en.wikipedia.org/wiki/Control_flow#Loops
On Tue, 2007-09-18 at 12:13 -0400, James Kosin wrote:
Anyone have a good script to generate an HTML file for a directory listing?
If you're using Apache, it can do that all by itself. You can even customise what it does above and below the listing.
The following very simple BASH script generates a file with a listing of the current directory, vaguely similar to how Apache generates one.
echo "<html><head><title>testing</title></head><body><h1>testing</h1>" for file in * do echo "<div><a href="$file">$file</a></div>" done echo "</body></html>"
You could do something like that, but you'd probably want to expand on it.
On 9/18/07, James Kosin jkosin@beta.intcomgrp.com wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Anyone have a good script to generate an HTML file for a directory listing?
There's also autoIndex.php - I occasionally use it b/c it has thumbnail and search options.
Chris
Anyone have a good script to generate an HTML file for a directory listing?
I use this to generate an index.html for the cartoons I have in a directory. It works in the current directory and generates an index.html file with links to all the other files.
---------------------- start ------------------------------ #!/bin/bash #set -xv
dir=`/bin/pwd`
if [ -f index.html ] then echo "remove index.html from directory $dir manually" exit 1 fi
dir=`basename $dir` tmpfile=/tmp/bi$$ find . -type f -print | sed -e 's!^./!!' -e 's! !%20!g' | sort > $tmpfile
echo "<html>" > index.html echo "<head>" >> index.html echo "<title>$dir</title>" >> index.html echo "<META NAME="GENERATOR" CONTENT="build_index.html.sh">" >> index.html echo "</head>" >> index.html echo "<body>" >> index.html echo "<h1>$dir</h1>" >> index.html
for i in `cat $tmpfile` do j=`echo "$i" | sed -e 's!%20! !g'` echo "<br><a href="$i">$j</a>" >> index.html done
rm $tmpfile
echo "</body>" >> index.html echo "</html>" >> index.html
------------------------end ------------------------------
Bob S Phoenix, AZ