Here is a nice way to loop trough nested layers using the DOM.The script is just counting the layers and layer sets and displaying the elapsed time but easily can be edited for other purposes.One important thing is that the script is not going straight wich means that loops in the following way:

1) All document's layers2) All main sets3) Nested sets, nested sets …

P.S. People with CS2 will be lucky, its performing a lot faster in that version.

This one loops trough all visible layers except for first hidden layers in the sets. I dont know how is with versions higher than CS3 but CS2 performs much faster. My best result was to loop trough 471 layers/Sets ( all visible ) for 54 seconds in CS2 and 2 and a half minutes in CS3.