使用perl清理电脑上重复文件实现代码(续)
(编辑:jimmy 日期: 2024/11/27 浏览:3 次 )
复制代码 代码如下:
#!/usr/bin/perl
use File::DirWalk;
use File::Basename;
use Data::Dumper;
use warnings;
use strict;
my $dw = new File::DirWalk;
my %files;
fileparse_set_fstype("MSWin32");
$dw->onFile(
sub {
my ($file) = @_;
push @{$files{basename($file)}->{"Paths"}},$file;
$files{basename($file)}->{"Num"} += 1;
return File::DirWalk::SUCCESS;
}
);
my $hTrace;
open $hTrace, '> Trace.txt';
select $hTrace;
$dw->walk('D:/old/perl');
my @newFiles;
while( my ($k, $v) = each %files)
{
if($v->{"Num"} > 1)
{
#print $k."\n";
#print Dumper($v);
push @newFiles,
{
"Name"=>$k,
"Paths"=>$v->{"Paths"},
"Num"=>$v->{"Num"}
}
}
}
#print Dumper(@newFiles);
@newFiles = sort {($a->{"Num"}) <=> ($b->{"Num"})} @newFiles;
print Dumper(@newFiles);
close $hTrace;
#!/usr/bin/perl
use File::DirWalk;
use File::Basename;
use Data::Dumper;
use warnings;
use strict;
my $dw = new File::DirWalk;
my %files;
fileparse_set_fstype("MSWin32");
$dw->onFile(
sub {
my ($file) = @_;
push @{$files{basename($file)}->{"Paths"}},$file;
$files{basename($file)}->{"Num"} += 1;
return File::DirWalk::SUCCESS;
}
);
my $hTrace;
open $hTrace, '> Trace.txt';
select $hTrace;
$dw->walk('D:/old/perl');
my @newFiles;
while( my ($k, $v) = each %files)
{
if($v->{"Num"} > 1)
{
#print $k."\n";
#print Dumper($v);
push @newFiles,
{
"Name"=>$k,
"Paths"=>$v->{"Paths"},
"Num"=>$v->{"Num"}
}
}
}
#print Dumper(@newFiles);
@newFiles = sort {($a->{"Num"}) <=> ($b->{"Num"})} @newFiles;
print Dumper(@newFiles);
close $hTrace;
下一篇:perl Socket编程实例代码