Tcl equivalent for UNIX “cp -pL” command

后端 未结 1 1417
生来不讨喜
生来不讨喜 2021-01-22 12:25

What is Tcl equivalent for UNIX \"cp -pL\" command? I cannot find it in file command description

1条回答
  •  北海茫月
    2021-01-22 13:01

    For a single file: a) Get the real path to the file. b) Copy it. c) Set the attributes, modification time and access time.

    Unfortunately, there does not appear to be any way to set the change time (creation time on Windows).

    set fn sourcefn
    set tofn targetfn
    set nfn [file normalize [file readlink $fn]]
    file copy -force $nfn $tofn
    foreach {key} [list attributes mtime atime] {
      set temp [file $key $nfn]
      file $key $tofn {*}$temp
    }
    

    This is the pure Tcl solution that will work on unix, Mac OS X and Windows. Of course you could just do:

    exec cp -pLf $from $to
    

    References: file

    0 讨论(0)
提交回复
热议问题