Export layers into separate folders

I’m producing a ton of directional sprites for a game that I will be modyfying and exporting all the time.

The frames for the 8 directions are on separate layers and I need them exported to 8 separate folders so the frames in each folder have exact same names. I can do this manually but I wonder if there’s a way to make script that would automate the process and do basically this:

  • export each frame from each layer, name it by it’s tag + tagframe number to a folder named by it’s layer name (and also create the folder if it doesn’t exist)

Is this something that can be done with a script? and any directions how to make one? This would save me a ton of work.