假设我使用glob
和glob
捕获目录中的文件数:
llength
我想使用该数字,并根据另一个目录中文件的数量在llength
循环中增加它。
# For this example, suppose llength returned 4.
set number_of_images [llength [glob -nocomplain -directory $destination_folder -type f *]]
我的问题是,根据文档,foreach
返回一个字符串:
将列表视为列表,并返回一个十进制数字符串,并给出数字其中的元素。
我可以将其转换为foreach file [glob -nocomplain -directory $source_folder -type f *] {
puts [incr $number_of_images]
# I want to start the count at 5, and increment by 1 with each loop. incr fails to
# do so, as well as mathfunc::int.
}
并使用它吗?
问题在于您使用llength
。 int
命令用于递增包含整数而不是整数
value
的variable。只需从以下位置更改代码:incr
...到...
incr