-5

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

Jill448
  • 1,745
  • 10
  • 37
  • 62

2 Answers2

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

my @paths = File::Find::Rule->name('foo')->in(@dirs);
ikegami
  • 367,544
  • 15
  • 269
  • 518
1
#!/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" ); 
Sobrique
  • 52,974
  • 7
  • 60
  • 101