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

Copying sub directories

P: 12
Hi,
I would like to know how to copy certain types of files from a group of directories into another group of directories.
Jul 1 '08 #1
Share this Question
Share on Google+
3 Replies


eWish
Expert 100+
P: 971
What have you tried? In the meantime look into mkdir, readir, File Find and File::Copy to get you started.

--Kevin
Jul 1 '08 #2

P: 12
Hi,
i am trying to copy 1 set of files to a folder from an existing directory tree.
Can you please tell me what is wrong with this code?

Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
  3. use File::Copy;
  4. use File::Glob;
  5.  
  6. my $Src_Dir = 'C:\Documents and Settings\abcd';
  7. my $Dest_Dir_Gel = 'C:\gel';
  8. my $Dest_Dir_Res = 'C:\Results';
  9.  
  10. Sub dir_read
  11. {
  12.  # parse directory and sub directories for files
  13.  
  14.  # Declarations
  15.  my @Dir_List;
  16.  my @Gel_List;
  17.  my @Res_List;
  18.  my $Dir_Name = $_[0];
  19.  
  20.  # Create directories with module name 
  21.  mkdir "$Dest_Dir_Gel\$Dir_Name";
  22.  mkdir "$Dest_Dir_Res\$Dir_Name";
  23.  
  24.  foreach (@Dir_List){
  25.  
  26.   opendir(cDIR, $Dir_Name);
  27.  
  28.   # List the .gel and .res files 
  29.   @Gel_List = <*.gel>;
  30.   @Res_List = <*.res>;
  31.  
  32.   #copy files to folder
  33.   foreach (@Gel_List){
  34.     copy($_,"$Dest_Dir_Gel\$Dir_Name");
  35.   }
  36.  
  37.   #copy  files to  folder
  38.   foreach (@Res_List){
  39.     copy($_,"$Dest_Dir_Res\$Dir_Name");
  40.   }
  41.  
  42.  closedir(cDIR);
  43.  }
  44. }
  45.  
  46. &dir_read($Src_Dir);
Jul 2 '08 #3

nithinpes
Expert 100+
P: 410
The variable $Dir_Name is causing the problem. You are passing $Src_Dir as argument to dir_read subroutine. Hence, the line,
Expand|Select|Wrap|Line Numbers
  1.  my $Dir_Name = $_[0];
  2.  
will assign 'C:\Documents and Settings\abcd' to $Dir_Name. So, the line
Expand|Select|Wrap|Line Numbers
  1. mkdir "$Dest_Dir_Gel\$Dir_Name";
  2.  
will be like mkdir "C:\gel\C:\Documents and Settings\abcd" :(

process the argument for read_dir() to get only the desired string as sub-folder structure.
Jul 3 '08 #4

Post your reply

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