Scrpit LUA bulk rename layers


I’m making a script to rename all the layers of a file by string.
I’m using the already existing script for renaming tags.

local sprite = app.activeSprite

for i, layer in ipairs(sprite.layers) do

local name = layer .name
layer .name = (string.gsub(name, "old string", "new string"))


I replaced all the “tag(s)” by “layer(s)”, and it almost worked but it only changed elements that are on top of a hierarchy (everything inside a group remained untouched).

I don’t know how to affect the inside of a hierarchy.

I see Layer.layers and Layer.parent in the API but I don’t understand how to use it.
Or maybe use a condition with