Link to home
Start Free TrialLog in
Avatar of tankergoblin
tankergoblin

asked on

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?
Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia image

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
Avatar of tankergoblin
tankergoblin

ASKER

i dont have extract package

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.
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
are you using linux ??
im using Archive::Zip;
i also tried rename as below
rename ("c:/a.txt","d:/a.txt") or die "File move failed $!";

cannot also
ASKER CERTIFIED SOLUTION
Avatar of Lee Wadwell
Lee Wadwell
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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..
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial