Skip to main content
Please don't just link to a pastebin, these have a tendency to disappear, making your answer useless.
Source Link
Mat
  • 54.9k
  • 11
  • 164
  • 143

This perl script will extract each .zip file into its own subdirectory. Run the script more than once to handle nested zip files. It does not delete .zip files after extraction but you could make that change by adding an unlink() call.

http://pastebin.com/RyQbZeaf

#!/usr/bin/perl -w

# This script unzips all .zip files it finds in the current directory
# and all subdirectories.  Contents are extracted into a subdirectory
# named after the zip file (eg. a.zip is extracted into a/).
# Run the script multiple times until all nested zip files are
# extracted.  This is public domain software.

use strict;
use Cwd;

sub process_zip {
    my $file = shift || die;
    (my $dir = $file) =~ s,/[^/]+$,,;
    (my $bare_file = $file);
    $bare_file =~ s,.*/,,;
    my $file_nopath = $bare_file;
    $bare_file =~ s,\.zip$,,;
    my $old_dir = getcwd();
    chdir($dir) or die "Could not chdir from '$old_dir' to '$dir': $!";
    if (-d $bare_file) {
        chdir($old_dir);
        # assume zip already extracted
        return;
    }
    mkdir($bare_file);
    chdir($bare_file);
    system("unzip '../$file_nopath'");
    chdir($old_dir);
}

my $cmd = "find . -name '*.zip'";
open(my $fh, "$cmd |") or die "Error running '$cmd': $!";
while(<$fh>) {
    chomp;
    process_zip($_);
}

This perl script will extract each .zip file into its own subdirectory. Run the script more than once to handle nested zip files. It does not delete .zip files after extraction but you could make that change by adding an unlink() call.

http://pastebin.com/RyQbZeaf

This perl script will extract each .zip file into its own subdirectory. Run the script more than once to handle nested zip files. It does not delete .zip files after extraction but you could make that change by adding an unlink() call.

#!/usr/bin/perl -w

# This script unzips all .zip files it finds in the current directory
# and all subdirectories.  Contents are extracted into a subdirectory
# named after the zip file (eg. a.zip is extracted into a/).
# Run the script multiple times until all nested zip files are
# extracted.  This is public domain software.

use strict;
use Cwd;

sub process_zip {
    my $file = shift || die;
    (my $dir = $file) =~ s,/[^/]+$,,;
    (my $bare_file = $file);
    $bare_file =~ s,.*/,,;
    my $file_nopath = $bare_file;
    $bare_file =~ s,\.zip$,,;
    my $old_dir = getcwd();
    chdir($dir) or die "Could not chdir from '$old_dir' to '$dir': $!";
    if (-d $bare_file) {
        chdir($old_dir);
        # assume zip already extracted
        return;
    }
    mkdir($bare_file);
    chdir($bare_file);
    system("unzip '../$file_nopath'");
    chdir($old_dir);
}

my $cmd = "find . -name '*.zip'";
open(my $fh, "$cmd |") or die "Error running '$cmd': $!";
while(<$fh>) {
    chomp;
    process_zip($_);
}
Source Link
John
  • 21
  • 1

This perl script will extract each .zip file into its own subdirectory. Run the script more than once to handle nested zip files. It does not delete .zip files after extraction but you could make that change by adding an unlink() call.

http://pastebin.com/RyQbZeaf