Changeset 25554

Show
Ignore:
Timestamp:
09.05.2012 14:33:01 (7 years ago)
Author:
ak19
Message:

Added mv_dir_contents subroutine (which is called from activate.pl) for moving the contents of src dir into target dir, so these can exist alongside of non-identically named items already existing in target dir, rather replacing target dir with src dir.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/util.pm

    r25533 r25554  
    179179} 
    180180 
     181# Move the contents of source directory into target directory 
     182# (as opposed to merely replacing target dir with the src dir) 
     183# This can overwrite any files with duplicate names in the target 
     184# but other files and folders in the target will continue to exist 
     185sub mv_dir_contents { 
     186    my ($src_dir, $dest_dir) = @_; 
     187     
     188    # Obtain listing of all files within src_dir 
     189    # Note that readdir lists relative paths, as well as . and .. 
     190    opendir(DIR, "$src_dir"); 
     191    my @files= readdir(DIR);  
     192    close(DIR);  
     193     
     194    # construct absolute paths 
     195    foreach my $file (@files) {  
     196        # process all except . and .. 
     197        unless($file eq "." || $file eq "..") {          
     198            $file = &util::filename_cat($src_dir, $file); # this is sufficient to overwrite this file's name in @files 
     199                    # don't seem to need a separate array to keep the updated absolute path versions of the filenames 
     200        }        
     201    } 
     202    &util::mv(@files, $dest_dir); 
     203} 
     204 
    181205 
    182206# copies a file or a group of files