Goal: 使用 File::Find 和 Time:😜iece 找到最新更新的檔案 (latest files)
Exp. Env: Vovo2000.Com ( AS Perl 5.8 + CPAN )
由於 Gallery 1.3.x 版還是用文字檔去當 DB,所以要取出
最新的幾張圖,有一定的難度,所以要用工具去幫忙找出
「最新更新的幾張圖~」 ( Latest Modified Images )
寫法如下,版權屬於 Vovo2000.Com,不過自由取用~ 😃
CPAN 萬歲!!! 😊
代碼:
use File::Find;
use Time:😜iece;
$timeOneDay = 86400;
$dayMultipler = 1;
$ByteCount = 0;
$fileAll = 0;
$fileJpg = 0;
$fileYes = 0;
$pathToTra = "C:/gallery";
$gt = localtime;
$t1 = $gt->epoch;
find(\&fileThumb, $pathToTra);
$gt = localtime;
$t2 = $gt->epoch;
print "Total KByte: ".($ByteCount/1024)."\n";
print "Total Scan: ".$fileAll."\n";
print "Total Jpeg: ".$fileJpg."\n";
print "Total Match: ".$fileYes."\n";
print "Total TimeCost: ".($t2-$t1)."\n";
sub fileThumb
{
$fileAll++;
if ((/thumb\.jpg$/) )
{
$fileJpg++;
my $lt = 0;
$lt = localtime;
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($_) or die "Unable to stat $_\n";
if ( $mtime > ($lt->epoch - $timeOneDay*$dayMultipler) )
{
print "[ $fileYes ]"."$File::Find::name ";
print $size." ".$ctime." ".$lt->epoch."\n";
$ByteCount += $size;
$fileYes++;
}
}
}
(2003-08-02 14:01)