copy_dir.pl
Go to the documentation of this file.
1 #! /usr/bin/perl
2 
3 #---------------------------------------------------------------------
4 # Given a mother directory and a daughter directory, the script tryies
5 # to copy (ln -s) all the files in the mother dir into the daughter
6 # If the file alredy exists, the link is not created.
7 # Mother dir is optional. Default is $GENIE/config
8 #
9 #
10 # [--mother-dir] : Source directory
11 # [--daughter-dir] : Destination directory
12 # [--spline-file] : {no argument} Copies only files with format <vflavor>_on_<target>_<Process>.xml
13 #---------------------------------------------------------------------
14 
15 $iarg=0;
16 foreach (@ARGV) {
17  if($_ eq '--mother-dir') { $mother_dir = $ARGV[$iarg+1]; }
18  if($_ eq '--daughter-dir') { $daughter_dir = $ARGV[$iarg+1]; }
19  if($_ eq '--spline-file') { $only_spline = 1; }
20  $iarg++;
21 }
22 
23 $mother_dir=$ENV{'GENIE'}."/config" unless defined $mother_dir;
24 $daughter_dir=$ENV{'PWD'} unless defined $daughter_dir;
25 
26 print "Selected source dir: $mother_dir \n";
27 print "Selected target dir: $daughter_dir \n";
28 
29 opendir(DIR, $mother_dir) or die $!;
30 
31 while (my $file = readdir(DIR) ) {
32 
33  # We only want files
34  next unless (-f "$mother_dir/$file");
35 
36  # Use a regular expression to find files ending in .xml
37  next unless ($file =~ m/\.xml$/);
38 
39  if ( defined $only_spline ) {
40  next unless ( index($file, "_on_") != -1 );
41 
42  my $under_counter = $file =~ tr/_//;
43  next unless ( $under_counter == 3 );
44  }
45 
46  if ( -f "$daughter_dir/$file" ) {
47  print "$file already present \n";
48  }
49  else {
50  # `$move_command`;
51  $link_command="ln -s $mother_dir/$file $daughter_dir";
52  print "$link_command \n";
53  `$link_command`;
54  }
55 
56 }
57 
58 closedir(DIR);