473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Copy function doesnt seem to work

Hi,
i am trying to copy files of a certain type into a different directory using perl,
The copy function doesnt seem to work.
Expand|Select|Wrap|Line Numbers
  1. my @dir_list;
  2.           my $sub_dir;
  3.           my $file_name1;
  4.           my $file_name2;
  5.       my @file_list_gel;       
  6.           my @file_list_res;
  7. #--------------LINE21
  8.       opendir(aDIR, $dir_root);
  9.       @dir_list = grep !/^\.\.?$/, readdir aDIR;
  10.           closedir(aDIR); 
  11.     # if .gel or .res file is found in the current directory make a copy in respective folder
  12.         foreach $sub_dir(@dir_list)
  13.         {    
  14.         # make subdirectories in TS and results folder                 
  15.                  mkdir "$dir_dest_gel\\$sub_dir" or die $!;
  16.          mkdir "$dir_dest_res\\$sub_dir" or die $!; 
  17. #------------Line 31
  18.         print"Sub directory :$sub_dir\n";
  19.  
  20.         opendir(DIR, "$dir_root\\$sub_dir");
  21.                 while ($_ = readdir(DIR))
  22.         {
  23.             if($_ =~ /\.gel/)
  24.                         { 
  25.                 print"File name: $_\n";
  26.                 print"Dest Dir: $dir_dest_gel\\$sub_dir";
  27.                              copy("$_", "$dir_dest_gel\\$sub_dir\\$_") or die $!;
  28.                      }
  29.              if($_ =~ /\.res/)
  30.                      { 
  31.                           copy("$_", "$dir_dest_res\\$sub_dir\\$_") or die $!;
  32.                      }
  33.         }               
  34.                 closedir(DIR);
  35.      }
  36.  
it is printing the file name and destination directory correctly,
but copy function is not copying the file
Jul 8 '08 #1
4 1644
KevinADC
4,059 Expert 2GB
You hopefully just need to use chomp:

Expand|Select|Wrap|Line Numbers
  1. opendir(DIR, "$dir_root\\$sub_dir");
  2. while ($_ = readdir(DIR))
  3. {
  4. chomp;
  5. if($_ =~ /\.gel/)
  6. .....
Jul 8 '08 #2
i just changed the code from copy to system(copy) and it works, so i guess i am not using perl's copy function correctly
Jul 10 '08 #3
KevinADC
4,059 Expert 2GB
Perl has no copy() function. I assume you loaded the File::Copy module?
Jul 10 '08 #4
numberwhun
3,509 Expert Mod 2GB
i just changed the code from copy to system(copy) and it works, so i guess i am not using perl's copy function correctly
For your reference, here is a list of Perl's built-in functions. You will find that, as Kevin said, there is no copy function. If you installed and used a module, then you have to use its functions in its prescribed manner, per its CPAN documentation page.

Regards,

Jeff
Jul 11 '08 #5

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

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
5
by: SOR | last post by:
Assuming you had a template folder and files on the webspace and you wanted to make a exact copy/rename of it with a username and password being the one and only difference - how would one do it ?...
8
by: Ram Baruch | last post by:
Hi, I'm trying to use the File.Copy() function. It works well when the desenation file is local (Like: C:\dest\dest.exe). The problem is that when I'm trying to copy to a destenation that starts...
6
by: Desmond Cassidy | last post by:
Hi, I'm sure this has been asked several times before but I'll risk it ;-) If I wish to save an Arraylist to another Arraylist and work on te original without affecting the contents of the new...
3
by: JamesB | last post by:
Hmm, this doesn't seem to work. I am probably tackling it completely the wrong way, but basically I want a function to receive two IP's and a subnet mask and return True if IP1 and 2 are on the...
5
by: sarathy | last post by:
Hi, I need to see the output of the program when no copy constructor is used. Since by default, there is an implicit one, how should i perform the override, so as to totally remove the copy...
12
by: mantrid | last post by:
Im trying to move a file but am having luck my code is below. The temp and target paths are valid as they echo correctly. but I cant get the copy() function to work, or the rename() function ...
10
by: colin | last post by:
Hi, I profile my code and find its spending a lot of time doing implicit conversions from similar structures. the conversions are mainly things like this class Point { implicit conversion...
0
by: Meganutter | last post by:
hello, first of all, im incorporating this in a Windows forms app, not sure if i am correct here. excuse me if i am wrong i am looking for an easy and fast way to copy 2 collums from db1 (dbf...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.