Update: Updated the code to a compilable verison as suggested
I am trying to get the list of latest files in each dir(for each project) under a specific path ($output) , excluding a single dir OLD
How can I frame a rule to achieve this?
use strict;
use warnings;
use Data::Dump;
use File::Find::Rule;
my $output = "/abc/def/ghi";
my @exclude_dirs = qw(OLD);
my $rule = File::Find::Rule->new; $rule->or($rule->new
->file()
->name(@exclude_dirs)
->prune
->discard,
$rule->new);
my @files = $rule->in("$output");
dd \@files;
Directory Structure
/abc/def/ghi
|--- Project1
|-- 2013
|-- foobar_2013_0812_154.txt
|-- 2014
|-- foobar__2014_0912_255.txt
|-- foobar__2014_0916_248.txt
|--- Project2
|-- 2013
|-- fbaz_2013_0812_154.txt
|-- 2014
|-- fbaz__2014_0912_255.txt
|-- fbaz__2014_0916_248.txt
|--- OLD
|-- projectX
Current Output:
/abc/def/ghi/Project1/
/abc/def/ghi/Project1/2013
/abc/def/ghi/Project1/2013/file1_project1.txt
/abc/def/ghi/Project1/20l4
/abc/def/ghi/Project1/2014/foobar_2014_0912_255.txt
/abc/def/ghi/Project1/2014/foobar_2014_0916_248.txt
/abc/def/ghi/Project2
/abc/def/ghi/Project2/2013
/abc/def/ghi/Project1/2013/file2_project1.txt
/abc/def/ghi/Project2/2014
/abc/def/ghi/Project2/2014/foobarbaz_2014_0912_255.txt
/abc/def/ghi/Project2/2014/foobarbaz_2014_0912_248.txt
Desired Output:
/abc/def/ghi/Project1/2014/foobar_2014_0912_255.txt
/abc/def/ghi/Project2/2014/foobarbaz_2014_0912_248.txt
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.