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

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}); } } }
  • Comment on Re^2: 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^3: Printing all the files that have both ".rtf" and ".ftp" by searching recursively in a given directory
by Anonymous Monk on Apr 12, 2011 at 15:27 UTC

    I only want to print the names of files

      So edit the code that prints out directories, and like comment it out or something :)
Re^3: Printing all the files that have both ".rtf" and ".ftp" by searching recursively in a given directory
by Anonymous Monk on Apr 12, 2011 at 18:00 UTC

    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);
        Are you saying you have a file named something like "foo.rtf.ftp" or "foo.ftp.rtf"? Just change the name strings to match your bizarre file names:
        use warnings; use strict; use File::Find::Rule; use Data::Dumper; my @files = File::Find::Rule->file() ->name( '*.rtf*.ftp', '*.ftp*.rtf' ) ->in( './' ); print Dumper(\@files);