Renaming Images and related .txt files

I’m doing some work on an old site with quite a big archive and i’m trying to have things organised in a more systematic way and one of the things I want to do is to have all the images renamed using the same scheme {page-slug}-{n}.jpg which is easy enough.

The problem is that both rename() and changeName() only update the name of the actual image and not the associated .jpg.txt file containing the meta information.

Am I missing something here? Is this the intended behaviour? Are there extra steps?

I dont know why thats happening - i just wanted to say i keep a copy of NameChanger installed for such big reorganisational jobs which can batch chage the files.

Can this work through directories and use parent folder as part of the name? Because I’m dealing with 10 folders, each with anything between 100 to 300 folders in it, all containing 5 to 10 images each. Which is why I was doing this thorugh kirby because I can traverse all the folder tree and update some 20k images at once.

it can do the recursive bit, yes. Not sure about picking up the parent folder name.

Sadly I don’t think it does. I’ll wait and see if @texnixe knows what’s going on here with the changeName() method

ChangeName() should actually work fine, just tested just in case, but also according to what the code does.

Thanks @texnixe I rewrote literally the same code, tested on another set of images and now it’s working. No idea why on that first batch of images didn’t work. I tried 5 or 6 times before posting on the forum just in case with no luck. Maybe i’ll check to see if it was something related to the name of the files.

With that many images, it might make sense to run this from the command line rather than in the browser, or do it in batches to prevent script timeouts.

Oh yeah I’m doing it in batches. I was testing using the images of a single post just to see if everything was working correctly.