无法获取文件的完整路径

小牛

我写了一个脚本,该脚本可以:

  1. 递归搜索文件
  2. 获取唯一的(所需的)文件
  3. 在远程放置的服务器上创建目录
  4. 将此文件复制到相应目录中

操作系统:Windows7

我陷入了4个步骤(将文件复制到相应目录中),因为我无法获取要复制的文件的完整路径。

错误:在New_UIbug_parser.pl第70行中使用未初始化的值$ full_path进行打印

我想补充的一件事是文件放置在不同的目录中。

这是我的屁股:

use strict;
use warnings;
use File::Find;
use File::Path qw(make_path);
use File::Copy;


my $path = $ARGV[0];
my @UniqueAnr = ();
my %seen = ();
my $foundAnr;
find({ wanted => \&GetappropriateFile }, $path);
my @all_file;
my $file_name;
sub GetappropriateFile
{
  my $file = $_;

  if (-f $file && $file =~ /traces[_d+]/)
       {
              #my $line;
              $file_name = $File::Find::name;
              open(my $fh, "<", $file) or die "cannot open file:$!\n";
              my @all_lines =<$fh>;
              my $i=0;
              foreach my $check (@all_lines){
            if( $i < 10){
                  if($check =~ /Cmd line\:\s+com\.android\..*/){
                  #print"$file_name\n";
                   push(@all_file,$file);
                  #push(@all_file,$file_name);
                 }  
                 $i++;
            }
            else{
                 last;
                }
                  #print "$file\n";
                  close($fh);

        }

    }

} 

foreach my $all_anr_file (@all_file)
{
unless ($seen{$all_anr_file}) 
    {
       # if we get here, we have not seen it before
        push(@UniqueAnr, $all_anr_file);
        $seen{$all_anr_file}++;

    }
}




for my $anr_file (@UniqueAnr)
{
chomp($anr_file);
print "$anr_file\n";
my $full_path = <$path.*/$anr_file>;
print $full_path;
(my $dir = $anr_file) =~ s/\.[^.]+$//;
my $new_dir = File::Spec->catdir('\\\\star\Source_Temp\test', $dir);
#print"$new_dir\n";
#make_path($new_dir);
copy($full_path, $new_dir) or die "Copy failed for file $anr_file: $!";

}
津巴布韦

在您的wanted子目录中,您可以访问当前正在使用的文件的完整路径$File::Find::name请参阅File :: Find的文档

这意味着您实际上并不需要发现的所有东西。您可以在wanted函数中完成所有操作


另外请注意,您可以使用uniq列表:: MoreUtils更换你foreach%seen解决方案。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章