这个是ftp实时更新文件列表的脚本···随便写了一下
#!/usr/bin/perl
use strict;
use File::Monitor;
my $title_on=1;
my $list_file='list.txt';
my @list=@{&get_folder($list_file)};
my @folders;
my @file_list;
my $create ='files_created';
#my $html='g:\\share\\今日更新列表(实时更新).htm';
my $html='F:\\share\\今日更新列表(实时更新).htm';
&check_folders(@list);
my $monitor=&create_monitor();
my $start_time=(localtime)[3];
print 'ftp Monitor is working now...please don\'t close it',"\n";
while (1)
{
#my @new_files;
#$_->$create?&put_out($_->$create): &is_tomorrow() for $monitor->scan;
for my $change ( $monitor->scan )
{
&put_out($change->$create) if $change->$create;
}
&is_tomorrow(); #new
sleep 2;
}
sub is_tomorrow
{
#my $html='E:\\movie\\今日更新列表(实时更新).htm';
if((localtime)[3]!=$start_time)
{
unlink $html||die "can't del file:$!\n";
$start_time=(localtime)[3];
$title_on=1;
}
}
sub put_out
{
#my $ref_new_files=shift;
my @new_files=@_;
my $ftp='ftp://10.50.25.1/';
#my $html='E:\\movie\\今日更新列表(实时更新).htm';
open WEB,">>",$html;
print WEB "请使用迅雷单线程下载,直接点解可能下载不了","\n" if $title_on;
$title_on=0;
while(my $file=shift @new_files)
{
next if -d $file;
next if $file=~/.*htm$/ig;
if($file=~/^f/i) #new
{
$file=~s{.*?\\(.*?)\\(.*)}{动漫\\$1\/$1\/$2}g;
$file=~s{\\}{\/}g;
}
else
{
$file=~s{.*?\\share\\(.*)}{$1}g;
$file=~s{\\}{\/}g;
}
my $site=$ftp.$file;
print WEB ',$site,'">',$file,' ',"\n";
}
#close WEB;
}
sub get_folder
{
my $dir_list=shift;
my @dirs;
die "can't find $dir_list:$!\n" unless -e $dir_list;
open IN,"<",$dir_list;
while(<IN>)
{
chomp;
next if /^#/;
push @dirs,$_;
}
close IN or die "can't close handle:$!\n";
return \@dirs;
}
sub check_folders
{
my @list=@_;
if(@list)
{
print "watch target:\n";
#print $_,"\n" foreach (@folders);
@folders=grep{-e $_ and -d _} @list;
print $_,"\n" for @folders;
}
else
{
print "请设置需要监视的目录\n";
print '按ENTER键退出';
<STDIN>;
exit(0);
}
}
sub create_monitor
{
my $monitor = File::Monitor->new;
while ( my $target = shift @folders)
{
$monitor->watch(
{
name => $target,
recurse => 1
}
);
}
return $monitor;
}
|
阅读(907) | 评论(1) | 转发(0) |