如何复制目录内的文件而不是 TCL 中的整个目录?
How to copy files within directory rather than a whole directory in TCL?
由于软件升级文件保存到错误的目录,现有脚本无法运行,我需要修复它。文件保存在项目文件中更深的几个文件夹中。我知道我可以使用这个命令来复制目录
file copy -force "path_files_to_copy" "path_to_copied_into"
虽然它会复制文件夹,但路径指向的不是每个单独的文件夹和该文件夹中的文件。如何将指定路径中的所有内容复制到新位置而不仅仅是父位置?
编辑
我解决了它,虽然在我看来我使用的步骤比实现相同目标所需的步骤多 10 倍,但它确实有效。主要是将tcl产生的“\”改成“\”,将其算作字符。
# Copy files from this folder
set from $take_from ;# Everything from this folder
set to $bring_to ;# To this folder
set var [glob -dir $from *;]
set wordList [regexp -inline -all -- {\S+} $var] ;# makes a list
for { set i 0 } {$i < [ llength $var ] } { incr i } { ;# Loop through files found
set file_path [ lindex $var $i ]
set count 0
set indx 0
set limit [string length $file_path]
set file_path_f $file_path
set incra 0
while { $count < $limit } {
set t [string index $file_path $count]
if { "$t" == "\" } {
set temp $count
set indx $temp
set ll [expr $count + $incra]
set file_path_f [string replace $file_path_f $ll $ll "\\"]
incr incra
}
incr count
}
# FILES DESTINATION
file copy -force $file_path_f $to
}
使用glob
command枚举源目录下的条目,分别复制:
foreach f [glob -directory $sourceDir -nocomplain *] {
file copy -force $f $targetDir
}
由于软件升级文件保存到错误的目录,现有脚本无法运行,我需要修复它。文件保存在项目文件中更深的几个文件夹中。我知道我可以使用这个命令来复制目录
file copy -force "path_files_to_copy" "path_to_copied_into"
虽然它会复制文件夹,但路径指向的不是每个单独的文件夹和该文件夹中的文件。如何将指定路径中的所有内容复制到新位置而不仅仅是父位置?
编辑
我解决了它,虽然在我看来我使用的步骤比实现相同目标所需的步骤多 10 倍,但它确实有效。主要是将tcl产生的“\”改成“\”,将其算作字符。
# Copy files from this folder
set from $take_from ;# Everything from this folder
set to $bring_to ;# To this folder
set var [glob -dir $from *;]
set wordList [regexp -inline -all -- {\S+} $var] ;# makes a list
for { set i 0 } {$i < [ llength $var ] } { incr i } { ;# Loop through files found
set file_path [ lindex $var $i ]
set count 0
set indx 0
set limit [string length $file_path]
set file_path_f $file_path
set incra 0
while { $count < $limit } {
set t [string index $file_path $count]
if { "$t" == "\" } {
set temp $count
set indx $temp
set ll [expr $count + $incra]
set file_path_f [string replace $file_path_f $ll $ll "\\"]
incr incra
}
incr count
}
# FILES DESTINATION
file copy -force $file_path_f $to
}
使用glob
command枚举源目录下的条目,分别复制:
foreach f [glob -directory $sourceDir -nocomplain *] {
file copy -force $f $targetDir
}