Search the web
Sign In
New User? Sign Up
perl-beginner · Perl Beginners Mailing List
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
copy & move function   Message List  
Reply | Forward Message #26304 of 26744 |
Re: copy & move function

Following is another code using loop. But I have some problem in the
loop as the file is copied to all my directories and it is unable to
copy the z.txt to the subdirectories. eg: /abc/FD, pqt/FD, /sde/FD.



#!\usr\bin\perl
use warnings;
mkdir("F:/usr/eg/abc", 0777) || print $!;
mkdir("F:/usr/eg/abc/FD", 0777) || print $!;
mkdir("F:/usr/eg/pqt", 0777) || print $!;
mkdir("F:/usr/eg/pqt/FD", 0777) || print $!;
mkdir("F:/usr/eg/sde", 0777) || print $!;
mkdir("F:/usr/eg/sde/FD", 0777) || print $!;
print "Enter the file to copy: ";
$fl = <>;
chomp($fl);
use File::Copy;
opendir DIR, "."; # . is the current directory

while ( $filename = readdir(DIR) )
{
if(-d $filename && $filename ne'.' && $filename ne '.')
{
print "copied $fl to: " , $filename,"\n";
copy($fl,$filename);
}
}
rename('F:/usr/eg/abc/FD/z.txt','F:/usr/eg/abc/FD/abc.txt');
rename('F:/usr/eg/pqt/FD/z.txt','F:/usr/eg/pqt/FD/pqt.txt');
rename('F:/usr/eg/sde/FD/z.txt','F:/usr/eg/sde/FD/sde.txt');

--- In perl-beginner@yahoogroups.com, "ramesh.govinda"
<ramesh.govinda@...> wrote:
>
> Hello All,
>
> I have a small query about this code. I had earlier asked you this
> problem, but that time I had mentioned the directories in terms of
> number s and so it was easier to use foreach loop. But now i need to
> create directories which is a mixture of variables and number and then
> I need to copy the file and give the respective folder name to the file.
>
> Could anyone let me know if I could go for loop for this code
>
> #!\usr\bin\perl
> use warnings;
> mkdir("F:/usr/eg/abc", 0777) || print $!;
> mkdir("F:/usr/eg/abc/FD", 0777) || print $!;
> mkdir("F:/usr/eg/pqt", 0777) || print $!;
> mkdir("F:/usr/eg/pqt/FD", 0777) || print $!;
> mkdir("F:/usr/eg/sde", 0777) || print $!;
> mkdir("F:/usr/eg/sde/FD", 0777) || print $!;
> print "Enter the file to copy: ";
> $fl = <>;
> chomp($fl);
> use File::Copy;
> copy('F:/usr/eg/z/z.txt','F:/usr/eg/abc/FD');
> rename('F:/usr/eg/abc/FD/z.txt','F:/usr/eg/abc/FD/abc.txt');
> copy('F:/usr/eg/z/z.txt','F:/usr/eg/pqt/FD');
> rename('F:/usr/eg/pqt/FD/z.txt','F:/usr/eg/pqt/FD/pqt.txt');
> copy('F:/usr/eg/z/z.txt','F:/usr/eg/sde/FD');
> rename('F:/usr/eg/sde/FD/z.txt','F:/usr/eg/sde/FD/sde.txt');
>
> Regards,
> Ramesh
>





Sun Jul 20, 2008 3:10 pm

ramesh.govinda
Offline Offline
Send Email Send Email

Forward
Message #26304 of 26744 |
Expand Messages Author Sort by Date

Hello All, I have a small query about this code. I had earlier asked you this problem, but that time I had mentioned the directories in terms of number s and...
ramesh.govinda
Offline Send Email
Jul 20, 2008
2:38 pm

Following is another code using loop. But I have some problem in the loop as the file is copied to all my directories and it is unable to copy the z.txt to the...
ramesh.govinda
Offline Send Email
Jul 20, 2008
3:10 pm

... the ... to ... Hello Ramesh Perhaps to following (untested) code will do what you want. Chris ... #!/usr/bin/perl # those are 'forward' slashes. ... use...
a_z0_9_blah
Offline Send Email
Jul 20, 2008
7:37 pm

Hi Chris, The code works out well. By using loop the code is very short now. The only line which i could not understand is my ($rename) = $dir =~...
ramesh.govinda
Offline Send Email
Jul 20, 2008
10:57 pm

... The ... The left side of the assignment is a list (items within the parentheses) of 1 item, $rename. This gives list context to the regular expression...
a_z0_9_blah
Offline Send Email
Jul 21, 2008
12:33 am

Hi Chris, Thanks!.That was really awesome explanation. Will checkout the links for further understanding. Regards, Ramesh ... From: a_z0_9_blah...
Ramesh Govinda
ramesh.govinda
Offline Send Email
Jul 21, 2008
6:23 am

Hello Chris, I just have a small query adding to my previous problem. I am just curious to know if I could have this desired output. My input file is...
Ramesh Govinda
ramesh.govinda
Offline Send Email
Jul 22, 2008
6:25 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help