     1	# This  script  will copy the whole  source directory  tree
     2	# to the  destination. Be carefull  that if the root target
     3	# ( destination ) directory does not exists then it will be
     4	# created. This script will work only on Windows platforms,
     5	# but with some  small changes  will work on unix  as well.
     6	# The destination files will be over  writen if they exist.
     7	# Xxxxxx Xxxxxx
     8	# xxxx@xxxxxxxx.xxxxx.xxx
     9	
    10	my $source_directory = 'f:/temp' ;
    11	my $target_directory = 'c:/temp' ;
    12	
    13	&xcopy($source_directory,$target_directory);
    14	
    15	############# xcopy subroutine #############
    16	
    17	sub xcopy {
    18	my ($pwd,$i)=($_[0],$i++);
    19	die "You have not defined the \$target_directory variable, sorry...\n" if    $target_directory eq "";
    20	die "You have not defined the \$source_directory variable, sorry...\n" if -d $source_directory !=1;
    21	 if (( -d $target_directory !=1 ) && ( -e $target_directory ==1 ))
    22	 {die "Can't continue because a file has target's dir name\n";}
    23	 elsif ( -e $target_directory !=1 )
    24	 { mkdir $target_directory || die "Couldn't create dir : $target_node\n"}
    25	opendir ($i,$pwd) || die "Can't list $pwd\n";
    26	while (my $source_node=readdir $i) {
    27	 next if $source_node=~/^\.*$/;
    28	$source_node       = $pwd.'/'.$source_node;
    29	( my $relative_node ) = $source_node =~/$source_directory(.*)/;
    30	$target_node       = $target_directory.$relative_node;
    31	if (-d $source_node==1) {
    32	 if (( -d $target_node !=1 ) && ( -e $target_node ==1 )) {
    33	 die "Can't mkdir $target_node because a same name file exist\n" }
    34	 elsif ( -e $target_node !=1 ) {
    35	 print "mkdir  $target_node\n";
    36	 mkdir $target_node || die "Couldn't create dir : $target_node\n" } }
    37	else {
    38	 if (( -d $target_node ==1 ) && ( -e $target_node ==1 )) {
    39	 warn "Can't copy $target_node because a same name dir exist\n"; }
    40	 else {
    41	 print "coping $source_node to $target_node\n" if -e $target_node !=1 ;
    42	 (my $copy_target_node) = $target_node; $copy_target_node=~s/\//\\/g  ;
    43	 (my $copy_source_node) = $source_node; $copy_source_node=~s/\//\\/g  ;
    44	 `$ENV{ComSpec} /c copy /b $copy_source_node $copy_target_node`;      }
    45	}
    46	&xcopy($source_node) if -d $source_node==1 }
    47	closedir $i}
    48	
    49	
