tcl - 如果目标目录已存在,如何复制目录

标签 tcl

我想将目录复制到特定目标,但出现错误,因为目标目录已经存在。所以我添加了 -force 标志但得到了同样的错误。

示例:

file copy -force my_dir $target_path

将“my_dir”复制到“my_dir”时出错:文件已存在

纯tcl中有没有办法在已经存在的目录上复制目录?

最佳答案

file copy文档说明:

Trying to overwrite a non-empty directory, overwrite a directory with a file, or overwrite a file with a directory will all result in errors even if -force was specified.

因此,在复制新目录之前,您必须删除/清空/清理$target_path。我想知道您是否会发现这个 tcllib 模块有用:fileutil::traverse

关于tcl - 如果目标目录已存在,如何复制目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17065260/

相关文章:

regex - 用正则表达式匹配一个字符串

java - 如何用Java Hook 到系统级expect?

tcl - 如何获取当前脚本的路径?

string - 如何在Tcl中简洁地连接字符串?

linux - 如何在后台运行 eval spawn ssh 和 expect?

regex - 从 tcl 中的方括号中提取字符串

linux - exec 命令被卡住

tcl 字符串替换

namespaces - Tcl 错误 : command already exists in namespace "::"

list - 如何将 tcl 中的列表用作多个字符串的参数(而不是一个字符串)?