in reply to Re: perl robocopy to temp mapped drive.
in thread perl robocopy to temp mapped drive.

This does it, thanks for the help Perl Monks!
# $destination is the full unc path to the share directory # $extract is the full path the the individual file to be copied my $drive = netUse ($destination); copyDat ($extract, $drive); sub netUse { my @net_use_output; my $output; chomp $_[0]; $_ = $1 if($_[0]=~/(.*)\\$/); print "\nnet use \* \"$_[0]\""; #my $output = `net use \* \"$_[0]\" 2>&1|`; open TASK, "net use \* \"$_[0]\" 2>&1|" or die "cannot map $_[0]" +; while (<TASK>) { print "\n"; print; #chomp; #chop; push (@net_use_output, $_); #return $_; } print join(", ", @net_use_output); print "\n"; print "\n"; print "-----\n"; print @net_use_output[0]; $output = $2 if(@net_use_output[0]=~/^(Drive\s)([A-Z])\:(.*)$/); print "\n"; print "\n"; print "-----\n"; print $output; return $output; } sub copyDat { my $file = basename($_[0]); my $path = dirname($_[0]); #$path .= "\\"; #This one's for James print "\n File: $file \n\n"; print "\n Dirname: $path \n\n"; #chomp $_[1]; #my $map = $_[1]; #my $map = $1 if($map=~/(.*)\\$/); print "\nROBOCOPY \"$path\" $_[1]\:\\ $file /B \n\n"; open TASK, "ROBOCOPY \"$path\" $_[1]\:\\ $file /B 2>&1|" or die "c +annot $!"; while (<TASK>) { print; #return $_; } print "\nnet use $_[1]\:\\ /delete \n\n"; open TASK2, "net use $_[1]\: /delete 2>&1|" or die "cannot $!"; while (<TASK2>) { print; #return $_; } }
- 3dbc