cp.tcl 783 B

1234567891011121314151617181920212223242526272829
  1. #/usr/bin/tclsh
  2. #
  3. # This is a TCL script that copies multiple files into a common directory.
  4. # The "cp" command will do this on unix, but no such command is available
  5. # by default on Windows, so we have to use this script.
  6. #
  7. # tclsh cp.tcl FILE1 FILE2 ... FILEN DIR
  8. #
  9. # This should be as simple as
  10. #
  11. # file copy -force -- {*}$argv
  12. #
  13. # But jimtcl doesn't support that. So we have to do it the hard way.
  14. if {[llength $argv]<2} {
  15. error "Usage: $argv0 SRC... DESTDIR"
  16. }
  17. set n [llength $argv]
  18. set destdir [lindex $argv [expr {$n-1}]]
  19. if {![file isdir $destdir]} {
  20. error "$argv0: not a directory: \"$destdir\""
  21. }
  22. for {set i 0} {$i<$n-1} {incr i} {
  23. set fn [file normalize [lindex $argv $i]]
  24. set tail [file tail $fn]
  25. file copy -force $fn [file normalize $destdir/$tail]
  26. }