1#! 2#[[BEGIN PROPERTIES]] 3# Type = Command 4# Order = 3.0 5# Interpreter = perl 6# Caption = Copy 7# Descr =Copy one or more files and/or directories into another 8# Descr =directory. Directories are copied recursively. 9# Descr = 10# Descr =Selection details: 11# Descr = 12# Descr = Source: The files and directories to be copied. 13# Descr = 14# Descr = Target: The target directory, or a single target file 15# Descr = to be overwritten by a single source file. 16# Icon = copy_file.tga 17# Hotkey = Ctrl+C 18#[[END PROPERTIES]] 19 20use strict; 21use warnings; 22BEGIN { require "$ENV{'EM_DIR'}/res/emFileMan/scripts/cmd-util.pl"; } 23 24if (IsFirstPass()) { 25 26 ErrorIfNoSources(); 27 ErrorIfNotSingleTarget(); 28 29 ConfirmIfSourcesAcrossDirs(); 30 31 my $message= 32 "Are you sure to copy, overwriting any existing target files?\n". 33 "\n". 34 "From:\n". 35 GetSrcListing(). 36 "\n". 37 "To:\n". 38 GetTgtListing() 39 ; 40 Confirm("Copy",$message); 41 42 SecondPassInTerminal("Copy"); 43} 44 45my @src=GetSrc(); 46my @tgt=GetTgt(); 47 48my $e=TermRunAndSync( 49 "cp", 50 ($Config{'osname'} eq 'linux' or $Config{'osname'} eq 'cygwin') ? ( 51 "-vfdpR" 52 ) 53 : ( 54 "-fpR" 55 ), 56 "--", 57 @src, 58 $tgt[0] 59); 60 61my @newTgt=(); 62if (-d $tgt[0]) { 63 for (my $i=0; $i<@src; $i++) { 64 my $f=fileparse($src[$i]); 65 my $p=catfile($tgt[0],$f); 66 if (-e $p) { 67 push(@newTgt,$p); 68 } 69 } 70} 71if (@newTgt > 0) { 72 SendSelectKS(@newTgt); 73} 74else { 75 SendUpdate(); 76} 77 78TermEnd($e); 79