Tcl equivalent for UNIX “cp -pL” command

落爺英雄遲暮 提交于 2020-01-11 11:09:12

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/40615492/tcl-equivalent-for-unix-cp-pl-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!