467,882 Members | 1,212 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,882 developers. It's quick & easy.

copying files or a directory

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
  • viewed: 1802
Share:
5 Replies
numberwhun
Expert Mod 2GB
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
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 2GB
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 2GB
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
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.

Similar topics

3 posts views Thread by Robert Tarantino | last post: by
5 posts views Thread by Ian Davies | last post: by
10 posts views Thread by Martin Ho | last post: by
17 posts views Thread by Kerr | last post: by
3 posts views Thread by Phil Galey | last post: by
6 posts views Thread by Jim Heavey | last post: by
2 posts views Thread by Jerad Rose | last post: by
2 posts views Thread by Alan Bak | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.