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

Hi Perl Monks,
Is File::Find is only for Directory search?
can we use File::Find for EAR or WAR to see the inside files

Replies are listed 'Best First'.
Re: How to use File::Find for EAR
by ikegami (Patriarch) on Nov 29, 2007 at 07:17 UTC

    File::Find scans file systems. It won't help you.

    I seem to remember JAR files being nothing but zip files, in which case you could use Archive::Zip. I don't know about EAR and WAR.

Re: How to use File::Find for EAR
by roboticus (Chancellor) on Nov 29, 2007 at 10:56 UTC
    Anonymous Monk:

    ikegami has it right. EAR is an "Enterprise" jar, and WAR is (IIRC) a "Web" jar.

    I've never played with Archive::Zip before, so I just did a trivial bit to verify that it's a ZIP file:

    #!/usr/bin/perl -w use strict; use warnings; use Archive::Zip; use Data::Dumper; my $INFName = shift or die "missing filename!"; my $arch = Archive::Zip->new($INFName); die "Can't find/read/parse $INFName!" if !defined $arch; my @t = $arch->memberNames; print Dumper(\@t);
    When used on a WAR file I have lying about, it shows:

    NBKI44V@B000F1FA4379F ~/PerlMonks $ ./ArchTar.pl /DOS/c/Program\ Files/Java/jdk1.6.0/db/lib/derby.war $VAR1 = [ 'WEB-INF/', 'WEB-INF/web.xml' ];
    HTH!

    ...roboticus

    Update: Added link to Archive::Zip.

Re: How to use File::Find for EAR
by andreas1234567 (Vicar) on Nov 29, 2007 at 12:44 UTC
    You can use File::Find to locate files whose filename indicate that they are of the type you want, then use Archive::Zip to inspect those files:
    use strict; use warnings; use Data::Dumper; use File::Find; use Archive::Zip qw( :ERROR_CODES :CONSTANTS ); my $dir = q{/opt/ibm/db2/V9.5/samples/}; my @files = (); find( sub { return unless -f; # skip non-files push @files, $File::Find::name if m/.*(war|ear)$/i; }, $dir ); foreach my $file (@files) { my $zip = Archive::Zip->new(); if ($zip->read($file) == AZ_OK) { my @members = $zip->memberNames(); print qq{$file has } . scalar(@members) . q{ member(s)}; } else { die "failed to open $file"; } } __END__
    $ perl -l 653779.pl /opt/ibm/db2/V9.5/samples/java/Websphere/OptimisticLocking.war has 76 +member(s) /opt/ibm/db2/V9.5/samples/java/Websphere/AccessEmployee.ear has 10 mem +ber(s) /opt/ibm/db2/V9.5/samples/repl/asnqwxml/stockticker/dist/stockticker.w +ar has 15 member(s)
    --
    Andreas
      Hi great monks
      What a beautifull solution thanks a lot
      is this solution appilicable for JAR files