2016-11-15 125 views

回答

2

对于单个文件: a)获取文件的真实路径。 b)复制它。 c)设置属性,修改时间和访问时间。

不幸的是,似乎没有任何方法来设置更改时间(在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 
} 

这是纯粹的Tcl解决方案,可以在unix,Mac OS X和Windows上运行。当然,你可能只是这样做:

exec cp -pLf $from $to 

参考文献:file

+0

很棒的回答。我特别喜欢使用'exec'的建议。 –