奇科電腦 回奇科電腦首頁奇科電腦LPI課程資訊奇科電腦Embedded課程資訊奇科電腦Cisco課程資訊奇科電腦Programming課程資訊奇科電腦Smartphone App課程資訊
Tech Tips17  Using Perl to move the latest file in a folder to another folder?

Author: Ben|Date: 2009/03/27|Back to Tech Tips

#!/usr/bin/perl

use File::Copy;

if ( @ARGV != 2 )
{
print "Usage: $0 <from_directory> <to_directory> \n\n";
exit 1;
}

my $latest_file = '';

opendir( DIR, "$ARGV[ 0 ]" );

while ( $file = readdir( DIR ) )
{
next if $file =~ /^\.\.?$/;
$file_time{ $file } = -C $file;
foreach ( keys %file_time )
{
$latest_file = $file if -C $file < $file_time{ $_ };
}
}

move ($latest_file, "$ARGV[ 1 ]" );


Best Browse: 1024x768 Copyright 2010 GeeGo Systems, Ltd.
service@geego.com.tw|DL: 0800-296-296|3F., No.60, Zhulun St., Zhongshan Dist., Taipei City 104, Taiwan (R.O.C.)|02-2711-6373