Welcome to Dream.In.Code
Become an Expert!

Join 149,604 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,904 people online right now. Registration is fast and FREE... Join Now!




Problem in unzipping the zip files

 
Reply to this topicStart new topic

Problem in unzipping the zip files

avik1612
27 Sep, 2007 - 10:50 PM
Post #1

New D.I.C Head
*

Joined: 27 Sep, 2007
Posts: 4


My Contributions
Hi,

I have created a script to extarct a set of zip files in a particular folder to another destination . In the destination folder a folder would be created with the name of zip file and it would be extracted in that folder with the name of zip file.

It is working well but when the zip file have subdirectories i.e folder inside folder. It in ignore the subdirectory and extract the whole contents into a single folder

What is wrong with my code

i have pasted the code for ur reference

# Script to unzip the zip files to a particular destination creating the folder with the name of zip file

use Archive::Zip;
use Archive::Tar;
use File::Copy;
use File::Find;
use File::Basename;

my @ext;

find(\&search, "D:/aaa");

sub search
{
if ((/\.zip$/) )
{
push @ext, $File::Find::name;
#print "@ext\n";
}

}

my @name1;
foreach my $fname(@ext)
{
my ($name, $path, $suffix) = fileparse($fname, '\.[^\.]*');

my $n = "D:/a/";
my $name1 = join("/",$n,$name);
mkdir $name1,0755;
print "\n\n Made Folder ";
print STDOUT $name, "\n";


my $zipname = $fname;

#my $destinationDirectory = 'D:\a';
my $destinationDirectory = $name1;

my $zip = Archive::Zip->new($zipname);
foreach my $member ($zip->members)
{
next if $member->isDirectory;
(my $extractName = $member->fileName) =~ s{.*/}{};
$member->extractToFileNamed("$destinationDirectory/$extractName");
}
print "\n Finished Extraction";
}

Thanks in Advance
Avi
User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Problem In Unzipping The Zip Files
28 Sep, 2007 - 12:40 AM
Post #2

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 238



Thanked: 6 times
Dream Kudos: 50
My Contributions
already answered on the other forum:

next if $member->isDirectory;
User is offlineProfile CardPM
+Quote Post

avik1612
RE: Problem In Unzipping The Zip Files
28 Sep, 2007 - 12:45 AM
Post #3

New D.I.C Head
*

Joined: 27 Sep, 2007
Posts: 4


My Contributions
QUOTE(KevinADC @ 28 Sep, 2007 - 01:40 AM) *

already answered on the other forum:

next if $member->isDirectory;



i am new to this forum i did not get what suggestion you have given because the
next if $member->isDirectory;

I tried by removing this line but it is still giving the same problem
i have already used

Thanks
avi

This post has been edited by avik1612: 28 Sep, 2007 - 12:49 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:55PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month