2
0

copy.pl 966 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/local/bin/perl
  2. use Fcntl;
  3. # copy.pl
  4. # Perl script 'copy' comment. On Windows the built in "copy" command also
  5. # copies timestamps: this messes up Makefile dependencies.
  6. my $arg;
  7. foreach $arg (@ARGV) {
  8. $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob...
  9. foreach (glob $arg)
  10. {
  11. push @filelist, $_;
  12. }
  13. }
  14. $fnum = @filelist;
  15. if ($fnum <= 1)
  16. {
  17. die "Need at least two filenames";
  18. }
  19. $dest = pop @filelist;
  20. if ($fnum > 2 && ! -d $dest)
  21. {
  22. die "Destination must be a directory";
  23. }
  24. foreach (@filelist)
  25. {
  26. if (-d $dest)
  27. {
  28. $dfile = $_;
  29. $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|;
  30. $dfile = "$dest/$dfile";
  31. }
  32. else
  33. {
  34. $dfile = $dest;
  35. }
  36. sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_";
  37. sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY)
  38. || die "Can't Open $dfile";
  39. while (sysread IN, $buf, 10240)
  40. {
  41. syswrite(OUT, $buf, length($buf));
  42. }
  43. close(IN);
  44. close(OUT);
  45. print "Copying: $_ to $dfile\n";
  46. }