Here a perl
script that will list all files including recursion over zip
and tar
files:
#!/usr/bin/env perl
use strict;
use warnings;
use Archive::Extract;
use File::Temp;
my ($indent) = (0);
die qq|Usage: perl $0 <zip-file>\n| unless @ARGV == 1;
printf qq|%s\n|, $ARGV[0];
$indent += 2;
recursive_extract( shift );
exit 0;
sub recursive_extract {
my ($file) = @_;
my $tmpdir = File::Temp->newdir;
my $ae = Archive::Extract->new(
archive => $file,
);
$ae->extract( to => $tmpdir->dirname );
for my $f ( @{ $ae->files } ) {
printf qq|%s%s\n|, q| | x $indent, $f;
if ( $f =~ m/\.(?:zip|tar)\z/ ) {
$indent += 2;
recursive_extract( $f );
}
}
$indent -= 2;
}
Some drawbacks: It doesn't cache already processed files, so if there are identical compressed files, it will extract and read them again. And it will search for compressed files looking only in their extension, not their content. So it can be improved for anyone who need or want it.
Assuming following script is named script.pl
, give the zip
file as argument, running it like:
perl script.pl myzip.zip
And in my test it yields something like:
myzip.zip
f1
f2
f3
f4
mytar.tar
f5
f6
f7
f8
testtar.tar
f11
f12
f13
f14
testtar.tar
f11
f12
f13
f14
testzip.zip
fd
fd2