比较两个目录中有没有同名的文件,有就输出目录及名字

#比较两个目录中有没有同名的文件,有就输出目录及名字

 

#!usr/bin/perl
use strict;
use warnings;
use Win32::OLE;   #??win32 OLE?

#Auther: lancer
#Data: 3/12/2010
#Function: Find and list the files with same name between two folders
#Version: 1.00

#TODO:Add recursion sub-folder

my $src_dir = "C://bt1//game//builds//iPhone//tmp//res";
my $dst_dir = "C://bt2//iphone//alchemo//res";
#get all the file name in source dir
my @src_file_list = glob("$src_dir//*");
#my @file_list = glob('C://Tools//*');

my $index = 0;

READ_ALL: foreach (@src_file_list){
    #print "$_/n";
    &ReadOneFile("$_",0);
    #last READ_ALL;
}

sub ReadOneFile($;$){ #read file and do something
  my $src_flie = $_[0];
  #print "$src_flie/n";
  $src_flie =~ /(.*[////])(.*)/;
  if($2){
    #print "$2/n";
    my $src_name = $2;
    my @dst_list = glob("$dst_dir//*");
    foreach (@dst_list){
      #print "$_/n";
      $_ =~ /(.*[////])(.*)/;
      my $dst_name = $2;
      if($src_name eq $dst_name ){
        print "find same file: $_/n";
        last;
      }
    }
  }
}

posted @ 2010-03-12 10:34  MXi4oyu  阅读(144)  评论(0编辑  收藏  举报