首頁 美術繪圖 | 美術設計 | 熱門標籤 | 首選 | 首頁宣傳 | 近期作品 論壇: 發表 | 美術工作 | 美術比賽 | 展覽活動 | 美術相關 | 一般討論 | 美術同好 CG 討論 :: Photoshop | Painter | 3D 行動 | AMP

【 立即註冊 】 : 更改個人資料 : : 登入

會員名稱: 登入密碼: 保持登入

[Perl] File::Find and Time::Piece (CPAN) 範例

發表新主題 回覆主題 討論區 Windows, Linux, Perl, PHP, C/C++, Driver, Web 理論、應用、硬體、軟體

| 1頁, 共1
人氣點閱:10883 發表人
[Perl] File::Find and Time::Piece (CPAN) 範例 2003-08-02 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++;
      }
   }
}

________________

美術插畫設計案子報價系統 v0.1 Beta
爪哇禾雀
Type



繪圖畫廊設計藝廊
攝影相簿留言板
最愛收藏分類標籤
暱稱: Type
註冊: 2002-11-30
發表: 11072
來自: vovo2000.com
V幣: 900702
Re: [Perl] File::Find and Time::Piece (CPAN) 範例 2003-08-02 14:06
/ / /

上面的測試執行結果如附件,
這樣我就可很清楚的知道,24 小時之內,哈仔更新了四張 Horace 的圖~

note.1: It's Pretty Dirty...不過沒辦法,期待 Gallery 2 出現!
note.2: 還是一句話 VIVAnia! CPAN!
use CPAN File::Find + Time::Piece to achieve Gallery Latest job_find_gallery.jpg
use CPAN File::Find + Time::Piece to achieve Gallery Latestjob_find_gallery.jpg



________________

美術插畫設計案子報價系統 v0.1 Beta
爪哇禾雀
Type



繪圖畫廊設計藝廊
攝影相簿留言板
最愛收藏分類標籤
暱稱: Type
註冊: 2002-11-30
發表: 11072
來自: vovo2000.com
V幣: 900702
Re: [Perl] File::Find and Time::Piece (CPAN) 範例 2003-08-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 "=>不改".$/;
            }
         
       }
          
    }
}

________________

美術插畫設計案子報價系統 v0.1 Beta
爪哇禾雀
Type



繪圖畫廊設計藝廊
攝影相簿留言板
最愛收藏分類標籤
暱稱: Type
註冊: 2002-11-30
發表: 11072
來自: vovo2000.com
V幣: 900702





資訊相關理論、技術、管理、應用、產品等
發表新主題 回覆主題