[英]Perl File::Find::Rule to exclude a single dir
I have the below shown directory structure. 我有以下显示的目录结构。
@project=('project1','project2')
; @project=('project1','project2')
; OLD
directory and its sub directories in @project
我想在@project
排除OLD
目录及其子目录 @project
. 我想在@project
所有项目的子目录中获取最新文件。 ie, for project1
, latest file is in sub directory 2014
, which is foobar__2014_0916_248.txt
即,对于project1
,最新文件位于子目录2014
,即foobar__2014_0916_248.txt
How can I frame a rule to achieve this? 如何构建规则来实现这一目标?
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;
My Dir Structure: 我的目标结构:
.
├── 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
As ikegami suggested, just do this in two steps. 正如池上建议,只需分两步完成。
The following does this using Path::Class
and Path::Class::Rule
以下使用Path::Class
和Path::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";
}
Outputs: 输出:
testing/project1 - testing/project1/2014/foobar__2014_0916_248.txt
testing/project2 - testing/project2/2014/foobarbaz__2014_0916_248.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.