Solved

how to unzip a file from one folder to another folder

Posted on 2009-05-07
12
738 Views
Last Modified: 2012-05-06
say no my zip file is in a folder and i want to move the unzip a file to b folder how?
0
Comment
Question by:tankergoblin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
12 Comments
 
LVL 25

Expert Comment

by:lwadwell
ID: 24333616
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
 
LVL 7

Author Comment

by:tankergoblin
ID: 24333711
i dont have extract package

0
 
LVL 7

Author Comment

by:tankergoblin
ID: 24333732
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:lwadwell
ID: 24333815
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
 
LVL 7

Author Comment

by:tankergoblin
ID: 24333989
are you using linux ??
0
 
LVL 7

Author Comment

by:tankergoblin
ID: 24333990
im using Archive::Zip;
0
 
LVL 7

Author Comment

by:tankergoblin
ID: 24333996
i also tried rename as below
rename ("c:/a.txt","d:/a.txt") or die "File move failed $!";

cannot also
0
 
LVL 25

Accepted Solution

by:
lwadwell earned 150 total points
ID: 24334042
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
 
LVL 84

Assisted Solution

by:ozo
ozo earned 100 total points
ID: 24334541
what error did you get when the rename failed?
0
 
LVL 7

Author Comment

by:tankergoblin
ID: 24351036
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
 
LVL 5

Assisted Solution

by:vikaskhoria
vikaskhoria earned 100 total points
ID: 24352956
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
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 150 total points
ID: 24397784
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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Which version of C should I use when Perl is too slow? 13 197
Migrate OTRS to newest version. 1 597
File Find regex problem 4 70
Formatting stings with pack and printf in perl 5 83
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question