Well, I just did a test and it doesn't work quite like I had planned.
$files works just fine anywhere after foreach (even outside the loop).
It doesn't work before the loop, though. That's what I'd really like to be able to do.
A couple of ideas to what I'm going for...
The page is very long. I'd like to make a navigation sidebar with small font links to each $item.
I'd also like to be able to dynamically set a background image in css for each $item.
In order to do that, I need those variables above the loop.
Maybe the loop can be further up, but there is a lot of code that shouldn't be duplicated (<body>, for instance).