how to unzip a file from one folder to another folder

say no my zip file is in a folder and i want to move the unzip a file to b folder how?
LVL 7
tankergoblinAsked:
Who is Participating?
 
lwadwellConnect With a Mentor Commented:
tankergoblin,

No ... I am using windows (Vista even) ...

I thought your were using windows are you were using c:/ and d:/ ... which are windows drive specifications.  Perhaps you should avoid those and use linux paths??

what is the folder/directory that contains the test file and what is folder/directory that you want move it into ?


BTW. And, if you are using Archive::Zip ... I am surprised you don't have Archive::Extract installed.  You sure you don't have it and cannot add it?

lwadwell
0
 
lwadwellCommented:
Hi tankergoblin,

To move (or copy) files I suggest you use the the File::Copy package  .. if the file was called "a.txt" then:

use File::Copy;
move("/old/folder/a.txt","new/folder") or die "File move failed $!";

To do the unzip into another folder, suggest you use the Archive::Extract package:

use Archive::Extract;
my $zip = Archive::Extract->new( archive => '/path/to/test.zip' );  # specify the file to unzip here
my $ok = $zip->extract( to => '/new/folder' ) or die $zip->error; # specify the folder to unzip into here


lwadwell
0
 
tankergoblinAuthor Commented:
i dont have extract package

0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
tankergoblinAuthor Commented:
below is use for testing

#!/usr/bin/perl
use File::Copy;

move("c:/a.txt","d:/a.txt") or die "File move failed $!";

i receive error saying that
file move failed bad file descriptor at c:/test.pl line 4.
0
 
lwadwellCommented:
tankergoblin,

What perl distro are you using?  Could you add the Archive::Extract package?

What are you using to unzip (where is it from) as I would need to look at its options to see if it can.


I could find nothing wrong with your short script for testing the move() ... it works for me, I had to use a sub-directory as I get permission problems using the root c:\ directory.  
Did you try using a different directory to the "root" directory?
Another guess, but try using DOS directory back slashes, you will need to use single quotes for that to work:

use File::Copy;
move('c:\a.txt','d:\a.txt') or die "File move failed $!";

lwadwell
0
 
tankergoblinAuthor Commented:
are you using linux ??
0
 
tankergoblinAuthor Commented:
im using Archive::Zip;
0
 
tankergoblinAuthor Commented:
i also tried rename as below
rename ("c:/a.txt","d:/a.txt") or die "File move failed $!";

cannot also
0
 
ozoConnect With a Mentor Commented:
what error did you get when the rename failed?
0
 
tankergoblinAuthor Commented:
i dont get any error
i use rename to move my file from one drive to another.
but after i run the file is not moved to the drive i want it to be..
0
 
vikaskhoriaConnect With a Mentor Commented:
I guess you were getting the error because of this reason:

You are using Windows and have used file separator as /, use \ instead.
i.e. C:\text.txt etc
This should help with the original error.
0
 
Adam314Connect With a Mentor Commented:
Are you trying to move an existing file to a new location, or extract a file from a zip to a specific location?

If moving an existing file, you can use the move function from File::Copy.
If extracting a file from a zip, you can use the Archive::Zip module.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.