如何增加从llength返回的数字?

问题描述 投票:0回答:1

假设我使用globglob捕获目录中的文件数:

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. } 并使用它吗?

int tcl
1个回答
0
投票
在Tcl中,一切都是字符串。是的,您可以递增包含整数(表示为十进制字符串)的变量。]​​>

问题在于您使用llengthint命令用于递增包含整数而不是整数

value

variable。只需从以下位置更改代码:incr
...到...

incr

© www.soinside.com 2019 - 2024. All rights reserved.