I believe merlyn at one time had something very similar to this on his website, although it hasn't been there for some time.

Put directories you want checked in __DATA__, with a trailing '/'. Will generate an HTTP header and a list of files in a div tag with ID "lastmodifiedfiles", for easy CSS application.

Caveat: this will not check subdirectories. For example, if you have a directory "shoes" and you want the program to search shoes/ and shoes/sandals and shoes/sneakers, you must put all three directories in __DATA__. This will probably be changed later.

#!/usr/bin/perl -w use strict; use vars qw( %files $file $dir $fh @files ); print "Content-type: text/html\n\n"; my $count = 1; while(<DATA>){ chomp $_; $dir = $_; $dir =~ s/\A\.\.\/httpdocs//ig; opendir($fh, $_); @files = grep(/\.s?html?$/, readdir($fh)); foreach $file (@files){ my $lm = -M "$_$file"; $files{$lm} = "$dir$file"; } } my @lastfiles = sort {$a <=> $b} keys %files; print q[<div id="lastmodifiedfiles">]; foreach(0..4){ print qq[ <a href="$files{$lastfiles[$_]}">$files{$lastfiles[$_]}</a>, + ]; my $days = $lastfiles[$_]; if($days > 1){ $days =~ /(\d+)\./; print qq[$1 days ago.<br>]; } else{ $days = ($days * 24); if($days > 2){ $days =~ /(\d+)\./; print qq[$1 hours ago.<br>]; } else{ $days = ($days * 60); $days =~ /(\d+)\./; print qq[$1 minutes ago.<br>]; } } } print q[</div>]; __DATA__ ../httpdocs/ ../httpdocs/shoes/ ../httpdocs/shoes/sandals/ ../httpdocs/shoes/sneakers/

Update: changed "@files = grep(/\.htm$|\.html/, readdir($fh));" to "@files = grep(/\.s?html?$/, readdir($fh));"

John J Reiser
newrisedesigns.com


In reply to Display a list of recently updated files on your webserver by newrisedesigns

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.