TCL脚本,用于遍历目录中的所有文件夹并执行一项功能
文件结构TCL脚本,用于遍历目录中的所有文件夹并执行一项功能,tcl,tk,vmd,vmdk,Tcl,Tk,Vmd,Vmdk,文件结构 File1 test.pdb xyz.txt File2 test.pdb xyz.txt File3 test.pdb xyz.txt 我想在目录中的所有文件夹中循环,并运行Tk控制台上文本文件autopsf.tcl中的以下代码: package require autopsf mol new test.pdb autopsf -mol 0 package require solvate solvate test_autopsf.psf test_autops
File1
test.pdb
xyz.txt
File2
test.pdb
xyz.txt
File3
test.pdb
xyz.txt
我想在目录中的所有文件夹中循环,并运行Tk控制台上文本文件autopsf.tcl中的以下代码:
package require autopsf
mol new test.pdb
autopsf -mol 0
package require solvate
solvate test_autopsf.psf test_autopsf.pdb -t 5 -o solvate
package require autoionize
autoionize -psf solvate.psf -pdb solvate.pdb -neutralize
我目前正在运行以下代码:
for d in ./*/ ; do
source autopsf.tcl
done
如果您不关心订单,您可以:
foreach dir [glob -type d *] {
# safety check
if {![file exists $dir/test.pdb]} continue
# code to do the work here; note that we have directories
}
您可能可以将包require
调用排除在外。设计良好的包可以正确地组合在一起,将它们放在顶部是一种使依赖性变得明显的有用方法
如果要对目录进行排序,请将
lsort
应用于glob
的输出。glob
的默认顺序是操作系统为我们提供的目录项,并且可以依赖于各种情况(包括文件年限等),因此不应该依赖于确定处理事项的代码。此代码适用于我:
foreach file [glob -nocomplain "./*/"] {
cd $file
source autopsf.tcl
cd ..
}
另外,如果在脚本中使用cd
,请务必小心。它可能会混淆您的代码。。。