my ($src, $trg) = @ARGV; die "$src isn't a directory" unless -d $src; die "$trg isn't a directory" unless -d $trg; `xcopy /s /e $src $trg`;
We check to make sure both arguments are really directories, then we invoke xcopy to do the dirty work. We could have also used:
system("xcopy /s /e $src $trg");
@hosts = `net view`; foreach (@hosts) { next unless m#\\\\#; chop; s/^(\S+).*/$1/; push @sorted, $_; } print join("\n", sort @sorted);
We run the command net view and capture the output as a list of lines. We then go through each line looking for hostnames (they start with \\), chop off newlines and comments, and add the matches to another list. We then sort the second list and print it.