参考我这个程序吧陆裤,这是个递归访问每个子目录,并列出文件。你在里面根据取出的文件,使用stat函数取出其文件大小并显示就可以了。
或者使用File::Find模块,也很简单的。
#!/usr/bin/perl -wl### REWRITE THIS USING File::Find
use File::Basename
use strict
use warnings
@ARGV or die "usage: $0 directory [depth]\n"
@ARGV == 2 and ($ARGV[1] > 0 or die "usage: $0 directory [depth]\n")
$main::WANT_SORTED_OUTPUT = 0
my $root = shift
my $depth = int(shift || -1)
my $indent = 0
my ($gap, $reg, $dir, $link, $spec, $stop, $unread) =
("| ", "|---", "+-", ">---", "*---", "++", "XXX-")
die "$root is not a directory\n" unless -d $root
recurse($root)
sub recurse {
my $dir = shift
print basename($dir) if !$indent++
unless (-r $dir) {
print " ", $gap x ($indent - 1), $unread
}
else {
local *DIR
opendir DIR, $dir
if ($main::WANT_SORTED_OUTPUT) {
早颂简for (map $_->[0], sort { $a->[1] cmp $b->[1] } map [ $_, lc ], readdir DIR) {
next if /^\.\.?$/
print " ", $gap x ($indent - 樱山1), (prefix("$dir/$_")), $_
recurse("$dir/$_") if $indent != $depth and -d "$dir/$_" and !-l "$dir/$_"
}
}
else {
while (defined(local $_ = readdir DIR)) {
next if /^\.\.?$/
print " ", $gap x ($indent - 1), (prefix("$dir/$_")), $_
recurse("$dir/$_") if $indent != $depth and -d "$dir/$_" and !-l "$dir/$_"
}
}
closedir DIR
}
print " ", $gap x (--$indent || 1)
}
sub prefix {
my $file = shift
-l $file ? $link :
-d $file && $indent != $depth ? $dir :
-d _ ? $stop :
-f _ ? $reg :
$spec
}
#!/usr/bin/perl#取文件行数
##循环开始清空文件
if (-f "tmp.out"){
open FILE,">tmp.out"
close FILE}
open( A, "<", "count.txt" )
while (<A>) {
$count = $_
槐乱 铅大档 }
print "上次记录的记录数为$count\n"
open(my $fh, '<', 'catalina.out')
$. = 0
while (<$fh>) {
($num=$.) if eof
}
print "文件最新的记录数为$num"."\n"
open( B, ">", "count.txt" )
print B ("$num\n")
if ( defined($count) 仿瞎&& $num != $count && $num !=0 )
{print "开始处理\n"
open( C, "<", "catalina.out" ) || die "$!\n"
while (<C>) {
if ($. > "$count" ){
open( D, ">>", "tmp.out" )
print D ("$_\n")
}
}}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)