Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How to extract .tar files in different directory?

Reply
Thread Tools

How to extract .tar files in different directory?

 
 
Dan
Guest
Posts: n/a
 
      02-15-2007
Hi, could anyone tell me how to do a perl script, which can
extract .tar files in
different directories?

e.g.

I have ./data/11/aaa/1a.tar, 1b.tar, 1c.tar
./data/22/bbb/2a.tar, 2b.tar, 2c.tar

how can I extract 1*.tar and 2*.tar files under /data directory into a
specified folder.

Since I am pretty new to perl, I dont know how to examine every sub-
directory
in the ./data, if there are any .tar files, then unzip it.
could you give me any examples.

Thanks a lot!

 
Reply With Quote
 
 
 
 
marora@gmail.com
Guest
Posts: n/a
 
      02-15-2007
On Feb 15, 4:16 pm, "Dan" <(E-Mail Removed)> wrote:
> Hi, could anyone tell me how to do a perl script, which can
> extract .tar files in
> different directories?
>
> e.g.
>
> I have ./data/11/aaa/1a.tar, 1b.tar, 1c.tar
> ./data/22/bbb/2a.tar, 2b.tar, 2c.tar
>
> how can I extract 1*.tar and 2*.tar files under /data directory into a
> specified folder.
>
> Since I am pretty new to perl, I dont know how to examine every sub-
> directory
> in the ./data, if there are any .tar files, then unzip it.
> could you give me any examples.
>
> Thanks a lot!


You can use File::Find to traverse a directory tree. http://
perldoc.perl.org/File/Find.html
>From perl you can execute any unix command using system("cmd").


Regards,
Manish

 
Reply With Quote
 
 
 
 
gf
Guest
Posts: n/a
 
      02-15-2007
On Feb 15, 2:16 pm, "Dan" <(E-Mail Removed)> wrote:
> Hi, could anyone tell me how to do a perl script, which can
> extract .tar files in
> different directories?
>
> e.g.
>
> I have ./data/11/aaa/1a.tar, 1b.tar, 1c.tar
> ./data/22/bbb/2a.tar, 2b.tar, 2c.tar
>
> how can I extract 1*.tar and 2*.tar files under /data directory into a
> specified folder.
>
> Since I am pretty new to perl, I dont know how to examine every sub-
> directory
> in the ./data, if there are any .tar files, then unzip it.
> could you give me any examples.
>
> Thanks a lot!


Something to consider...

Rather than do it purely in Perl, you might want to wrap a tar command
in backticks or a system() command and let the tar application handle
the problem. In that case just read up on the tar docs.

Sometimes it's easier to take advantage of Perl's ability to act as
glue, but we forget to do it when we're wearing our Perl colored
glasses.

 
Reply With Quote
 
au.danji@gmail.com
Guest
Posts: n/a
 
      02-16-2007
On Feb 15, 4:29 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> On Feb 15, 4:16 pm, "Dan" <(E-Mail Removed)> wrote:
>
>
>
> > Hi, could anyone tell me how to do a perl script, which can
> > extract .tar files in
> > different directories?

>
> > e.g.

>
> > I have ./data/11/aaa/1a.tar, 1b.tar, 1c.tar
> > ./data/22/bbb/2a.tar, 2b.tar, 2c.tar

>
> > how can I extract 1*.tar and 2*.tar files under /data directory into a
> > specified folder.

>
> > Since I am pretty new to perl, I dont know how to examine every sub-
> > directory
> > in the ./data, if there are any .tar files, then unzip it.
> > could you give me any examples.

>
> > Thanks a lot!

>
> You can use File::Find to traverse a directory tree. http://
> perldoc.perl.org/File/Find.html
>
> >From perl you can execute any unix command using system("cmd").

>
> Regards,
> Manish


Thanks for all reply, actually, I am running my script in windows XP,
so I can not use unix cmd.


 
Reply With Quote
 
gf
Guest
Posts: n/a
 
      02-16-2007
On Feb 16, 7:42 am, (E-Mail Removed) wrote:

> Thanks for all reply, actually, I am running my script in windows XP,
> so I can not use unix cmd.


Look at 7-Zip, which is an open-source app running on Windows that
nicely handles tar, plus other formats.

http://www.7-zip.org/

Wikipedia has lots to say...

http://en.wikipedia.org/wiki/Tar_%28file_format%29

 
Reply With Quote
 
Mumia W.
Guest
Posts: n/a
 
      02-16-2007
On 02/16/2007 08:42 AM, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Feb 15, 4:29 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>> [...]
>> From perl you can execute any unix command using system("cmd").
>>
>> Regards,
>> Manish

>
> Thanks for all reply, actually, I am running my script in windows XP,
> so I can not use unix cmd.
>
>


You can install the Perl module Archive::Tar to help you with the tar files.


--
Windows Vista and your freedom in conflict:
http://www.regdeveloper.co.uk/2006/1...eula_analysis/
 
Reply With Quote
 
au.danji@gmail.com
Guest
Posts: n/a
 
      02-16-2007
On Feb 16, 12:24 pm, "Mumia W." <paduille.4060.mumia.w
(E-Mail Removed)> wrote:
> On 02/16/2007 08:42 AM, (E-Mail Removed) wrote:
>
> > On Feb 15, 4:29 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> >> [...]
> >> From perl you can execute any unix command using system("cmd").

>
> >> Regards,
> >> Manish

>
> > Thanks for all reply, actually, I am running my script in windows XP,
> > so I can not use unix cmd.

>
> You can install the Perl module Archive::Tarto help you with thetarfiles.
>
> --
> Windows Vista and your freedom in conflict:http://www.regdeveloper.co.uk/2006/1...eula_analysis/




Thank for everyone's reply!!

Below is my perl code, which can unzip all .tar file from
one directory, however, since I have around 20 .tar files
in this directory(each one is 100MB), when the script running,
my pc becomes really slow, I guess that because Perl put them
into the memory, could anyone tell me if I can extract these big
..tar files without using large amount of my PC memory? Thanks!

This is my code:
================================================== ===========
opendir(DIR,"$localpath") || die("cannot open $localpath");

foreach $direntry (readdir(DIR))
{
if ($direntry =~ /tar/)
{
print "direntry tar is: $direntry\n";
if ($tar->read("$localpath/$direntry",1))
{
print "read $direntry successfully\n";
}

if ($tar->extract())
{
print "extract $direntry successfully\n";
}
}

}


================================================== ===============

Also I try to put the unziped files into a different folder, but the
$tar->extract_file is not working like below code, what is wrong with
that?

$tar->extract_file("$localpath/1.tar","$localpath/extract/test");


thanks a lot!

 
Reply With Quote
 
Mumia W.
Guest
Posts: n/a
 
      02-17-2007
On 02/16/2007 03:40 PM, (E-Mail Removed) wrote:
> On Feb 16, 12:24 pm, "Mumia W." <paduille.4060.mumia.w
> (E-Mail Removed)> wrote:
>> On 02/16/2007 08:42 AM, (E-Mail Removed) wrote:
>>
>>> On Feb 15, 4:29 pm, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>>>> [...]
>>>> From perl you can execute any unix command using system("cmd").
>>>> Regards,
>>>> Manish
>>> Thanks for all reply, actually, I am running my script in windows XP,
>>> so I can not use unix cmd.

>> You can install the Perl module Archive::Tarto help you with thetarfiles.
>>
>> --
>> Windows Vista and your freedom in conflict:http://www.regdeveloper.co.uk/2006/1...eula_analysis/

>
>
>
> Thank for everyone's reply!!
>
> Below is my perl code, which can unzip all .tar file from
> one directory, however, since I have around 20 .tar files
> in this directory(each one is 100MB), when the script running,
> my pc becomes really slow, I guess that because Perl put them
> into the memory, could anyone tell me if I can extract these big
> ..tar files without using large amount of my PC memory? Thanks!
>
> This is my code:


Please read and follow the posting guidelines for this newsgroup:
http://www.augustmail.com/~tadmc/clp...uidelines.html

Please start your scripts with

use strict;
use warnings;

and write your program to work with them. They will catch many errors
for you. Also read the documentation for Archive::Tar:
http://search.cpan.org/dist/Archive-...Archive/Tar.pm


> ================================================== ===========
> opendir(DIR,"$localpath") || die("cannot open $localpath");
>
> foreach $direntry (readdir(DIR))
> {
> if ($direntry =~ /tar/)
> {
> print "direntry tar is: $direntry\n";
> if ($tar->read("$localpath/$direntry",1))
> {
> print "read $direntry successfully\n";
> }
>
> if ($tar->extract())
> {
> print "extract $direntry successfully\n";
> }
> }
>
> }
>


I don't have Archive::Tar installed, but it sounds like you can enable
the "extract" option to have it automatically extract files when "read"
is called. Change into the desired directory and invoke "read" on the
$tar object.

>
> ================================================== ===============
>
> Also I try to put the unziped files into a different folder, but the
> $tar->extract_file is not working like below code, what is wrong with
> that?
>
> $tar->extract_file("$localpath/1.tar","$localpath/extract/test");
>
>
> thanks a lot!
>


If the above suggestion works, this should not be needed.


--
Windows Vista and your freedom in conflict:
http://techdirt.com/articles/20061019/102225.shtml
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Trying to extract different types of data from a singe file. JoeC C++ 7 08-02-2008 09:42 PM
How do i extract vidios when winrar wont extract them??? help plzzzzzzzz smuttdog@sc.rr.com Computer Support 2 12-23-2007 07:03 AM
how i can extract text from the PDF files,power point files,Ms word files? crazyprakash Java 4 10-30-2005 10:17 AM
Caching Different Xml files for different users Nita Raju ASP .Net 1 12-15-2004 07:10 AM



Advertisments