By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,710 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,710 IT Pros & Developers. It's quick & easy.

copying files or a directory

P: 51
hi,
I have got a list of files in a "list" as follows:
Expand|Select|Wrap|Line Numbers
  1.     foreach(@arr)
  2.     { 
  3.             copy ("$_", "/home/pavan/tmp") or die "copy failed: $! ";
  4.      }
  5.  
The path where the files are stored is /home/pavan/perl.
I need to copy all the files in perl directory to the temporary directory
"tmp" as in the copy statement. For that i used a package File::Copy.
I am able to print the files with print "$_ \n";
But unfortunately the copy statement is not working . I am not getting an error either.
So could u tell me how to copy all the files in perl to tmp directory? Also is there any method to copy the perl directory as a whole to tmp directory?

Thanks & Regards,
pavan.
Jun 17 '08 #1
Share this Question
Share on Google+
5 Replies


numberwhun
Expert Mod 2.5K+
P: 3,503
You say you can print the file names with the print statement, but does the file names include the full path? If you are executing the script from somewhere other than the directory where all of the files are located, then you will need to include the full path with something like this:

Expand|Select|Wrap|Line Numbers
  1. foreach(@arr)
  2. {
  3. copy ("/home/pavan/perl/$_", "/home/pavan/tmp") or die "copy failed: $! ";
  4. }
  5.  
Oh, and please use code tags next time when including code.

Regards,

Jeff
Jun 17 '08 #2

P: 51
hi ,
all the files which i like to copy in /tmp directory are in the directory /perl itself . so i used $_ directly without giving full path . I also tried the way just u have told me . I had given the full path. But it has not worked . Also there is no error. So, is there any alternative to do the above work?

Thanks & Regards,
pavan
Jun 17 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
hi,
I have got a list of files in a "list" as follows:
Expand|Select|Wrap|Line Numbers
  1.     foreach(@arr)
  2.     { 
  3.             copy ("$_", "/home/pavan/tmp") or die "copy failed: $! ";
  4.      }
  5.  
The path where the files are stored is /home/pavan/perl.
I need to copy all the files in perl directory to the temporary directory
"tmp" as in the copy statement. For that i used a package File::Copy.
I am able to print the files with print "$_ \n";
But unfortunately the copy statement is not working . I am not getting an error either.
So could u tell me how to copy all the files in perl to tmp directory? Also is there any method to copy the perl directory as a whole to tmp directory?

Thanks & Regards,
pavan.

I think the problem is you are copying all the files in the perl directory to the pavan directory into a file named tmp.

Assuming you are in the directory where the files are to be copied from:

Expand|Select|Wrap|Line Numbers
  1.     foreach(@arr)
  2.     { 
  3.             copy ("$_", "/home/pavan/tmp/$_") or die "copy failed: $! ";
  4.      }
  5.  
copy() takes two arguments, a file to copy from and a file to copy to.
Jun 17 '08 #4

numberwhun
Expert Mod 2.5K+
P: 3,503
I think the problem is you are copying all the files in the perl directory to the pavan directory into a file named tmp.

Assuming you are in the directory where the files are to be copied from:

Expand|Select|Wrap|Line Numbers
  1.     foreach(@arr)
  2.     { 
  3.             copy ("$_", "/home/pavan/tmp/$_") or die "copy failed: $! ";
  4.      }
  5.  
copy() takes two arguments, a file to copy from and a file to copy to.
Ouch! I completely missed the lacking "/" that was missing after the "tmp" dir name. C'est la vie.

Jeff
Jun 17 '08 #5

P: 51
Ouch! I completely missed the lacking "/" that was missing after the "tmp" dir name. C'est la vie.

Jeff
hi,
i think the files are not copying bcoz tmp is a directory in which system generated temporary files are stored? Can we copy files into a directory which contains system generated files?
Jun 18 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.