Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Re: globing directory names with spaces

by abhishes (Friar)
on Sep 16, 2002 at 14:21 UTC ( [id://198250]=note: print w/replies, xml ) Need Help??


in reply to Re: globing directory names with spaces
in thread globing directory names with spaces

works very well.

But it list *.java files only of the directory which I
specify.

What can I do to make it list all the *.java diles in the
direcotry which I specify and all its subdirectories as well?

thanks for your reply.

regards,
Abhishek.
  • Comment on Re: Re: globing directory names with spaces

Replies are listed 'Best First'.
Re^2: globing directory names with spaces
by Aristotle (Chancellor) on Sep 16, 2002 at 14:27 UTC
    Then you need to look into File::Find.
    use File::Find; my @java_file; find(sub { push @java_file, $File::Find::name if /\.java$/i }, "/desired/path");

    Makeshifts last the longest.

      Alternatively you could use File::Find::Rule
      use File::Find::Rule; my @files = File::Find::Rule->file() ->name('*.java') ->in('your/dir/here');
      Which will return a list of all the files with the .java extension in the given directory and all of it's subdirectories.
      HTH

      _________
      broquaint

      Hello All,
      thanks you so much for all the replies
      Here is what i wrote with File::Find
      #!/usr/bin/perl use strict; use warnings; use File::Find; my @java_files; my $pattern = shift; if ($pattern eq '') { print "defaulting the directory to the current one\n"; $pattern = '.'; } print "$pattern\n"; find(\&wanted, $pattern); foreach my $file (@java_files) { open OUTFILE, "$file"; while(<OUTFILE>) { print "$_\n"; } } my $java_files = @java_files; print "++ Total number of java files in project = $java_files\n"; sub wanted() { if (/\.java$/i) { push(@java_files, $_); } }
      The problem is that the contents of the files are not
      getting printed. because the file open is failing.
      the file open is failing because I have only the file name
      and not the complete path of the file. what can I do go get
      the complete file name in my java_file array?
        Did you read my reply? You would have noticed I was using $File::Find::name rather than $_ in the sub I pass to find because I anticipated just that problem. :-) See the docs to File::Find for more details.

        Makeshifts last the longest.

Re^3: globing directory names with spaces
by flounder99 (Friar) on Sep 16, 2002 at 14:28 UTC
    If you are getting that complicated maybe you should look at File::Find.

    --

    flounder

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://198250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-07-24 20:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.