It turns out that there was no single image file.Corrected code that used the error appeared.In variable [zmFindFilesCount] shows the number of files found.Look in the debugger.Now, if the files are not found, the cycle will not start.

Generally if the calculated search large numbers of files, you need to review the structure of the code. With this approach will be very long process.If the list of 50 such lines, and files found in 1000, it is easier to search for and delete existing files found and add to the list of results.I hope you understand what I'm saying.

I do not know ...I have this code load about 12,000 ways to images.After I disabled. Was found 18650 images.All this of course takes time.And for such operations need to look for a more productive solution.

I do not view some wrong... maybe the first "Return", which anyway is not needed, but, the code appear not wrong. Try to remove the first "Return" after the "If [SelectedDir]" but again I think probably this is not the problem...

Keep calm. Sometimes we cannot view the obvious. So don't worry too much, keep calm, relax and take the needed time to take a look at the code. At the least you have lucky: you know the code can work, so is just a question of time and patience you found the possible error and fix it. So keep calm.

I am perfectly calm David. But I lost a lot of time working on this script that works perfectly in a button, but not from a GoSub...

Very strange thing, even with the NB debugger, I can not click on my application. I can not even slow down the debugger, turn pause or stop the script. Windows sound is heard ... as usual. Only solution = Ctrl+Alt+Del.

What's really weird is that the sub-routine work properly with directories containing some images. But as soon as there is a large number of images (5000 +) it works very badly. I can not explain it, I see it.