#!perl
use warnings;
use strict;
###脚本在于防止录像爆盘,当D盘容量小于3G时,删除100天以外的文件。
my $path='d:\video';
my @size=`dir d:`;
my @b=split(/\s+/,$size[$#size]);
$b[3]=~s/,//g;
my $a=$b[3] / 1024 / 1024 /1024;
if ($a < 3) {
opendir(D, "$path") or die " video :$!";
my @dir=readdir(D);
for (@dir) {
my $filename= $_;
if ( -M "$path\\$filename" > 100){
chomp($filename);
if ( "$filename" eq '..' or "$filename" eq '.') {
next;
}
unlink($filename) ;
}
}
}
###在又看了一遍小骆驼以后
#!perl
use warnings;
use strict;
use Win32::DriveInfo;
###脚本在于防止录像爆盘,当D盘容量小于10G时,删除100天以外的文件。
my $disk='d:';
my $ddir="${disk}" . '/video';
my $logdir="${disk}" . '/videolog/';
my $logfile="${logdir}" . 'video_log';
if ( ! -d ${logdir} ) {
mkdir "${logdir}",0755 or die "cannot mkdir $logfile:!";
}
##获取today##
my $today=&localtime;
sub localtime {
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime();
$year+=1900;
$mon+=1;
"${year}/${mon}/$mday";
}
my @diskinfo=Win32::DriveInfo::DriveSpace("$disk");
###计算出以G为单位的空间
my $diskinfo_g=$diskinfo[$#diskinfo] / 1024 /1024 /1024;
print $diskinfo_g;
if ($diskinfo_g < 10) {
open F,">> ${logfile}" or die "cannot open ${logfile} :$!";
print F "-" x 35, "\n";
print F "$today \n";
opendir DH, "$ddir" or die "$!";
for my $file (readdir DH) {
next if $file eq ".." or $file eq ".";
if ( (-M "${ddir}/${file}") > 100) {
chdir "$ddir" or die "$!";
print F "$file \t" ;
unlink $file;
}
}
closedir DH;
}
print F "-" x 50, "\n";
print F "\n" x 5, ;
close F;
####不能用shell的思想来写perl
阅读(1756) | 评论(0) | 转发(0) |