1

我有下面显示的目录结构。

  1. 我想在我的@project 中获取项目名称。@project=('project1','project2');
  2. 我想排除OLD目录及其子目录@project
  3. 我想在@project. 即,对于project1,最新文件在子目录2014中,即foobar__2014_0916_248.txt

我如何制定规则来实现这一目标?

use strict;
use File::Find::Rule;
use Data::Dump;
my $output       = "/abc/def/ghi";
my @exclude_dirs = qw(OLD);
my @projects     = File::Find::Rule->directory->in("$output");
dd \@projects;

我的目录结构:

.
├── project1
│   ├── 2013
|        ├── file1_project1.txt
│   └── 2014
|         ├── foobar__2014_0912_255.txt
|         ├── foobar__2014_0916_248.txt
├── project2
│   ├── 2013
|        ├── file1_project2.txt
│   └── 2014
|         ├── foobarbaz__2014_0912_255.txt
|         ├── foobarbaz__2014_0916_248.txt
└── OLD
    └── foo.txt
4

1 回答 1

3

正如 ikegami 建议的那样,只需分两步执行此操作。

  1. 首先找到你的项目名称
  2. 二、查找最新文件

以下使用Path::ClassPath::Class::Rule

use strict;
use warnings;
use autodie;

use Path::Class;
use Path::Class::Rule;

my $testdir = dir('testing');

for my $project ( $testdir->children ) {
    next if !$project->is_dir() || $project->basename eq 'OLD';

    my $newest;

    my $next = Path::Class::Rule->new->file->iter($project);
    while ( my $file = $next->() ) {
        $newest = $file if !$newest || $file->stat->mtime > $newest->stat->mtime;
    }

    print "$project - $newest\n";
}

输出:

testing/project1 - testing/project1/2014/foobar__2014_0916_248.txt
testing/project2 - testing/project2/2014/foobarbaz__2014_0916_248.txt
于 2014-09-17T20:39:49.560 回答