-1

尝试编写一个脚本,在找到这些文件后在文件夹中搜索两个文件,然后它必须对另一个文件执行一些操作:

我正在为这个脚本使用 Windows。

以下是文件夹的层次结构:

                      Logs
                     / | \  
                 abc   def   xyz
                 / \   / \     /\
               ANR etc ANR etc ANR etc

等=文本文件。

我正在尝试做的事情:

我想检查 ANR 文件夹是否存在两个文件(pqr.txt 和 rst.txt),如果这些文件存在则对等进行操作,就像我必须读取一个特定的文本文件并在其中搜索一些关键字特定的文本文件。

我如何接近:

#!/bin/usr/perl -w
use strict; 
use Cwd; 
use File::Find; 
my $dir ="C:\APTscripts\APStress\Logs";

find(\&file_operation,$dir);

$first_file = @ARGV[0];
$sec_file= @ARGV[1];

sub file_operation
{
    my $file = $_;
    if(($file =~ /teaces/) && ($file =~ /traces.txt.bugreport/))
    {
        Do some opeartion 
    }
}

但是按照这种逻辑,我无法做任何我想做的事情。任何机构都可以帮助我解决这个问题。

4

1 回答 1

1

这个根据您的描述检查父文件夹:

sub file_operation {
    my $file = File::Spec->rel2abs($_);
    if(($file =~ /traces/) && ($file =~ /traces.txt.bugreport/)) {
        my ($parent) = ($file =~ m!(.*)/!);
        if (-f "$parent/ANR/pqr.txt" or -f "$parent/ANR/rst.txt") {
            print "Do some opeartion: $file $parent\n";
        }   
    }   
}
于 2013-05-21T07:43:49.990 回答