psychoto has asked for the wisdom of the Perl Monks concerning the following question:
The html file created looks correct except the modification stamp isn't accurate for the files. Thanks in advance....#!/usr/bin/perl -w use myhtml; use strict; print"Please enter the directory to be searched. "; chomp(my $dirname = <STDIN>); until(-d $dirname){ print"The directory entered is not valid.\nPlease enter a director +y to be searched. "; chomp($dirname = <STDIN>); } unless($dirname =~ /\\$/){ $dirname .= "\\"; } open OUT, ">dir_stuff.html" || die "Could not open file: !, $!"; my $beginning = &myhtml::start_doc($dirname); print OUT <<MYHTML; $beginning MYHTML print OUT "$dirname<br>\n"; &search($dirname, 0); my $ending = &myhtml::end_doc(); print OUT <<MYHTML; $ending MYHTML sub search(){ my($dir, $offset) = @_; my $fullname; opendir DIR, $dir; foreach my $file(readdir DIR){ next if ($file =~ /^\./); if($file =~ /\.pl$/){ $fullname = $dir . $file . "\\"; &printFile($file, $offset, $fullname, 0); } if($file =~ /\.html$/){ $fullname = $dir . $file. "\\"; &printFile($file, $offset, $fullname, 1); } if(-d $dir.$file){ &printFile($file, $offset, $fullname, 2); $fullname = $dir . $file. "\\"; &search($fullname, $offset + 1); } } } sub printFile(){ my @file_type = qw(perl html dir); my @file_color = qw(orange red green); my($file, $offset, $filename, $type) = @_; my $spacer; my $age; my $days_old = (-M $filename.$file); if($offset > 0){ $spacer ="|" . " " x (4 * $offset); } if ( $days_old <= 7 ){ $age = "<b><i>brand</i>new!</b>"; }elsif ( $days_old < 30 ){ $age = "<b>new!</b>"; }else{ $age = "";} print OUT $days_old; print OUT "$spacer|----<font color= $file_color[$type]>$file_type[ +$type]: $file</font> $age<br>\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File Test help with -M (modification age)
by CountZero (Bishop) on Dec 12, 2002 at 07:22 UTC | |
|
Re: File Test help with -M (modification age)
by particle (Vicar) on Dec 12, 2002 at 02:31 UTC | |
by psychoto (Novice) on Dec 12, 2002 at 02:41 UTC |