Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

I don't want to search subfolders

by jcalhky (Initiate)
on Jun 15, 2005 at 21:24 UTC ( #467063=perlquestion: print w/replies, xml ) Need Help??

jcalhky has asked for the wisdom of the Perl Monks concerning the following question:

I have this script that searches the given location. Right now it searches the subfolders in that directory. I don't want it to search the subfolders. What can I do to make my script only search the files in the directory?


find( \&filehandler, "L:\\renws\\billing\\uploadh");

for my $filename ( sort keys %directories ) {
    my @dirlist = @{$directories{ $filename } };
    if ( scalar @dirlist > 0 ) {
     for ( @dirlist ) {
     my $RP1file = $_;
     my $local_file1 ="C:\\$RP1file";
     my $ftp = Net::FTP->new($host,Timeout=>240);
        }   # if
    }   # for

sub filehandler {
#Check that it's a file, not a directory
    return unless -f $File::Find::name;

# Just take the filename, convert to lowercase
    my $nameonly = $_;

    # See if it's a RP1 file
    return unless $nameonly = /.RP1/;

$directories{ $nameonly }= [] unless defined $directories{$nameonly };
    push( @{$directories{ $nameonly } }, $_ );

Replies are listed 'Best First'.
Re: I don't want to search subfolders
by merlyn (Sage) on Jun 15, 2005 at 21:36 UTC
Re: I don't want to search subfolders
by YuckFoo (Abbot) on Jun 15, 2005 at 22:36 UTC
    File::Find::Rule has a maxdepth method to limit how far down the tree to look.


    #!/usr/bin/perl use strict; use File::Find::Rule; use Data::Dumper; my @dirs = ( 'L:\\renws\\billing\\uploadh', ); my @files = File::Find::Rule ->file() ->maxdepth(1) ->name(qr/.RP1/) ->in(@dirs); print Dumper \@files;
Re: I don't want to search subfolders
by borisz (Canon) on Jun 15, 2005 at 21:38 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://467063]
Approved by Zaxo
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2019-12-15 12:31 GMT
Find Nodes?
    Voting Booth?

    No recent polls found