in reply to change directory in windows and extract the files from a .zip file inside the folder
..My perl script is in this directory and .caz(form of zip) files are also there in this directory..
One way of achieving your aim is as follow:
#!/usr/bin/perl use warnings; use strict; use File::Copy qw(copy); use Archive::Extract; use Cwd qw(abs_path); my $current_directory = $ARGV[0] // '.'; $current_directory = abs_path $current_directory; chdir $current_directory or die "directory doesn't exist: $!"; opendir my $dh, $current_directory or die "can't open directory: $!"; while ( my $file = readdir $dh ) { chomp $file; next if $file eq '.' or $file eq '..'; if ( $file =~ m{(?<filename>(?<new_folder>.+?)\.zip)$} ) { mkdir $+{new_folder}; ## make the folder copy $+{filename}, $+{new_folder}; ## copy file to be extracted into it' +s folder # files extracted in it's folder my $extract_file = Archive::Extract->new( archive => $+{filena +me} ); $extract_file->extract( to => $+{new_folder} ) or die $extract_file->error; } } closedir $dh or die "can't close directory: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: change directory in windows and extract the files from a .zip file inside the folder
by sreevno (Initiate) on Sep 12, 2012 at 09:03 UTC | |
by roboticus (Chancellor) on Sep 12, 2012 at 10:57 UTC |