luckysing has asked for the wisdom of the Perl Monks concerning the following question:
Hi monks I have written a script to copy files from one directory to another.What I want to do is that I have a tar file which in turn has many tar files inside it .I am extracting the main tar file and then after iterating through all the tar files inside of the big tar file i create folder name based on the tar file for example :for a file named FILE1.tar I create a directory named FILE1.After this I want to copy the FILE1.tar to its respective directory and extract it there.The problem is I am not able to use the move command and my program only creates the directory.Forgot to mention that I get a message file exists when i compile my program.Thanks in advance
#!/usr/bin/perl -w use File::Copy; use strict; use Archive::Tar; my (@files,$i,$name,$ext,@file,$oldlocation,$tobe); my $tar = Archive::Tar->new(); $tar->read('some.tar'); $tar->extract(); @files=<*.tgz>; #print @files; for $i(0..$#files) { $file[$i]=do{local(@ARGV,$/)=$files[$i];<>}; ($name,$ext)=split(/\./,$files[$i]); mkdir("$name",0777)||print $!; $oldlocation="/home/newbie/ta/$file[$i]"; $tobe="/home/newbie/ta/$name/"; move ($oldlocation,$tobe); } exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: copy files from one directory to another
by morgon (Priest) on Aug 02, 2010 at 22:11 UTC | |
by luckysing (Novice) on Aug 03, 2010 at 21:20 UTC | |
|
Re: copy files from one directory to another
by ahmad (Hermit) on Aug 02, 2010 at 21:10 UTC | |
by luckysing (Novice) on Aug 02, 2010 at 22:11 UTC | |
by Anonymous Monk on Dec 20, 2011 at 05:15 UTC |