in reply to Printing all the files that have both ".rtf" and ".ftp" by searching recursively in a given directory

File::Find::Rule
use warnings; use strict; use File::Find::Rule; use Data::Dumper; my @files = File::Find::Rule->file() ->name( '*.rtf', '*.ftp' ) ->in( './' ); print Dumper(\@files);
Super Search where title contains all of "recurs", "direct" : ?node_id=3989;HIT=recurs%20direct;re=N
  • Comment on Re: Printing all the files that have both ".rtf" and ".ftp" by searching recursively in a given directory
  • Download Code

Replies are listed 'Best First'.
Re^2: Printing all the files that have both ".rtf" and ".ftp" by searching recursively in a given directory
by midnightmonk (Novice) on Apr 12, 2011 at 10:38 UTC
    use Filesys::Tree qw/tree/; my $sysTree = tree({ 'full' => 1,'max-depth' => 3,'pattern' => qr/\.rt +f|\.ftp$/ } ,'.'); files($sysTree); sub files { my %treeree = %{+shift}; for (keys %tree) { if ($tree{$_}->{type} eq 'f'){ print $_,"\n" }elsif ($tree{$_}->{type} eq 'd') { files($tree{$_}->{contents}); } } }

      I only want to print the names of files

        So edit the code that prints out directories, and like comment it out or something :)

      When I run the above script on a directory I get the following output even there are files with same name but with both extensions .rtf and .ftp

      $VAR1 = [];

        It seems like the below code is printing the files with .rtf or .ftp files,I want to print files that has both .rtf and .ftp extension.Can someone advise?

        use warnings; use strict; use File::Find::Rule; use Data::Dumper; my @files = File::Find::Rule->file() ->name( '*.rtf', '*.ftp' ) ->in( './' ); print Dumper(\@files);