James Goe James Goe - 5 months ago 17
Perl Question

PERL: How do I find a parent folder of a known subfolder?

I'm new to PERL and I'm having some trouble getting a parent folder of a known sub-folder(s).
So I have a list of subfolders, let's say A, B, C, D, etc.
I know they are all scattered around in folders labeled (for eg.), 1, 2, 3, 4, etc.

So it can be like this:
1/A
1/B
2/C
3/D
3/E
etc.

I just want to iterate through each folder and find it's direct parent directory. Any ideas?

Answer
use File::Find::Rule qw( );

my @matches =
   File::Find::Rule
      ->name(qw( A B C D ))
      ->dir
      ->in('.');
Comments