微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

find file

#!/usr/bin/perl
 
# Written by Limeng
# May 27,2010 Changsha
 
use strict;
use File::Basename;
use warnings;

my $error_file = "error.txt";
my $clone_report_file = "clone_report.txt";
 
my @error;
my @path_list;
if ($ARGV[0] =~ /^(-h|-\?|\/\?|-help)$/i or !@ARGV) {
        print "\n Usage: find_clone [path1] [path2] [path3] ... \n\n Press Enter to close me ... \7";
         <STDIN>;
         exit;
}
else {
        foreach (@ARGV) {
                 s/\\/\//g;
                 chop if (/.*\/$/);
                 if (! -d $_) {
                          print " The path ($_) does not exist! Please check!\n\7";
                          push (@error,"The path ($_) does not exist! Please check!");
                  }
                  else { push(@path_list,$_); }
        }
        if (!@path_list) {
                 print "\n The path(s) you input are invalid,try again please!\n\n Press Enter to close me ... \7";
                 <STDIN>;
                 exit;
        }
}
 
$| = 1;
print "\n Scanning the path(s) ... ";
my @file_list;
foreach (@path_list) { readsub($_); }
print "Done!\n\n Analyzing ... \n\n";

my %files;

foreach my $path (@file_list) {
    my ($name,$dir) = fileparse($path);
    push @{$files{$name}},$path;
}

foreach my $file (keys %files) {
    if (@{$files{$file}} > 1) {
        print "@{$files{$file}}\n";
    }
}

 

#my @progress = ('-','-','\\','|','/','/'); #my $s = 0; #open FH,">$clone_report_file"; #foreach (keys %clone) { #        if (@{$clone{$_}} > 1) { #                 foreach(@{$clone{$_}}) { #                         my @stat = stat($_); #                         print FH time_transfer($stat[9]),"\t$_\n"; #                 } #                 print FH "\n"; #                 $clone++; #         } #} #if ($clone) { print qq~\n\n $clone group(s) clone files found,details see "$clone_report_file"!\n~; } #else { #        print qq~\n\n No clone files found!\n~; #        print FH qq~No clone files found!~; #} #close FH;   if (@error) {         open FH,">$error_file";         foreach (@error) { print FH "$_\n"; }          close FH;          print "\n ",$#error+1," error(s) ocurred,details please see \"$error_file\"!"; } else { print qq~\n No error ocurred!~; }   print "\n"; sub readsub {         my $file_t = shift;         if (-f $file_t)         {                 push(@file_list,$file_t);         }         if (-d $file_t) {                 opendir(AA,$file_t);                 my @list = readdir(AA);                 close (AA);                 my $file_to_act;                 foreach $file_to_act (sort @list)                 {                         if ($file_to_act =~ /^\.|\.$/) { next; }                         else                         {                                 readsub("$file_t/$file_to_act");                         }                 }         } }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐