if file.open("STATE","r") then
It seems easier than iterating the list which takes time.
BTW, I use this method in my init to stop PANIC looping:
if file.open('ABEND','r') then
print( 'init.lua ABORTING due to ABEND' )
file.close()
file.remove('ABEND')
do return end
end
file.open('ABEND','w') -- remove at normal end
file.close('ABEND')
If the file ABEND exists, then don't continue the init.lua processing.
At the end of a normal program: file.remove('ABEND')
So, if the file ABEND exists at the start, the program did not complete properly, usually some PANIC error. Don't bother trying to do it again, return to command mode.
Peter