Type(Type) 2003/8/2 14:01
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++;
}
}
}
Type(Type) 2003/8/2 14:06
上面的測試執行結果如附件,
這樣我就可很清楚的知道,24 小時之內,哈仔更新了四張 Horace 的圖~
note.1: It's Pretty Dirty...不過沒辦法,期待 Gallery 2 出現!
note.2: 還是一句話 VIVAnia! CPAN!
Type(Type) 2003/8/17 15:49
再來一個應用範例:
「把整個 site 的 web.vovo.idv.tw / www.vovo.idv.tw 全部改成 vovo2000.com」
輕輕鬆鬆統一域名~ ^_^
代碼:use File::Find;
sub mysub(); # Our custom subroutine
@directories = ("/這是你的 WWW 的目錄/htdocs/");
$tar1 = "web.vovo.idv.tw";
$tar2 = "www.vovo.idv.tw";
find(\&mysub, @directories);
sub mysub()
{
my ($filename) = $_;
if ( ($filename =~ /\.htm$/) || ($filename =~ /\.html$/) || ($filename =~ /\.php$/) )
{
print "$filename ";
if( open( FILE, $filename ) )
{
$a = join( "", <FILE> );
close( FILE );
$r = 0;
if ( $a =~ /$tar1/ )
{
$r = 1;
}
if ( $a =~ /$tar2/ )
{
$r = 1;
}
if ( $r == 1 )
{
### 先備份
if ( open( FILE, ">$filename".".orig" ) )
{
print FILE ($a);
close(FILE);
}
### 至換
$a =~ s/$tar1/vovo2000.com/g;
$a =~ s/$tar2/vovo2000.com/g;
if ( open( FILE, ">$filename" ) )
{
print FILE ($a);
close(FILE);
}
print "=============>改".$/;
}
else
{
print "=>不改".$/;
}
}
}
}
(10,985 views)
© Vovo2000.com Mobile Version 小哈手機版 2024