Kill windows in batch

I accidentally generated a few hundred tables because of a wrong-placed command in a loop and wanted to kill these tables using Killwindow command. However I wasn't able to reference the window by string returned from winlist or winname. What declaration should I use ahead of these strings to be able to reference the window or tables that I wanted to close, or how will Killwindows recognize windows that need to be killed? Thank you!
I think Killwindows needs to take a single name at a time. You can't pass a list. I think I ran into this problem in a different form.

Create a loop and go through the winlist.

Andy
Thank you Andy!
my code is as follows but I cannot seem to pass the string to killwindow...It seems that I need to specify that "windowname" refers to a window to kill so that Igor knows..,

function killwindows()

string list = winlist("*", ";", "WIN:2")
variable i

for (i=0;i<itemsinlist(list); i+=1)

string windowname = stringfromlist (i,list, ";")

killwindow windowname

endfor


end

Thanks!
mwpro wrote:

my code is as follows but I cannot seem to pass the string to killwindow...It seems that I need to specify that "windowname" refers to a window to kill so that Igor knows..


KillWindow takes a window name, not a string containing a window name.

Use $ like this:

function killwindows()

string list = winlist("*", ";", "WIN:2")
variable i

for (i=0;i<itemsinlist(list); i+=1)

string windowname = stringfromlist (i,list, ";")

killwindow $windowname

endfor


end



--Jim Prouty
Software Engineer, WaveMetrics, Inc.