Printing layer names automatically?

One more question:

How to modify the code so it doesn’t print parent layer’s name? Just the final sublayer’s name should be printed.