in reply to change directory in windows and extract the files from a .zip file inside the folder

Hi,

..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:


Please, modify the script below to suit your purpose:
#!/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: $!";

You might have to check Archive::Extract
Hope this helps.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me
  • Comment on Re: change directory in windows and extract the files from a .zip file inside the folder
  • Download Code

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

    Thanks, But my file is not zip or tar file. It is .caz file whihc uses command called cazipxp -u <filename> for extracting. when I am running the above command thru script it is extracting in the folder where I am executing the script but not to the new directory whihc I have created thru script. My .caz file is there in both parent and new directory. But I want to extract it in new directory. My .pl file is in parent directory. pls help

      sreevno:

      But my file is not zip or tar file. It is .caz file

      2teez knows that. That's why the reply said:

      Please, modify the script below to suit your purpose

      Some effort is required on your part. Since 2teez provided you a skeleton program that changes directories and extracts files from an archive, it's assumed that you can find the code to extract from a .caz file and alter the code appropriately.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.