perl list path of subdirectory using File::Find

98 Views Asked by At

How can I get all the paths of a subdirectory foo into an array in perl using File::Find

 abc\def\sdfg\gthrth\foo\
 abc\def\fgfdg\foo\
 abc\def\sdfgdsg\fgdfg\gfdgf\tytty\foo\
 abc\def\foo\

I want to get the full paths of all subdirectories foo inside directory abc\def into an array

2

There are 2 best solutions below

0
ikegami On BEST ANSWER
use File::Find::Rule qw( );

my @paths = File::Find::Rule->name('foo')->in(@dirs);
0
Sobrique On
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;

my @foo_paths;

sub is_it_foo {
   if ( m,^foo$, ) { 
       push ( @foo_paths, $File::Find::name ); 
   }
}

find ( \&is_it_foo, "abc/def" );