In Gulp, how do I rename image file names to match the folder name plus a number?
For example, I have:
img/cats/spotty.svg
img/cats/edgar.svg
and I'd like:
images/cats/cat1.svg
images/cats/cat2.svg
I have several other subfolders besides cats as well.
I've tried unsuccessfully to use rename but the addition of numbers makes it not work fully.
You can use the
gulp-rename
package and provide it with a custom function for renaming your files as they pass through. Use thepath
package for some utility, create a constructor function to generate a new hashtable of counters, and voila:Partially remixed from this answer by @OverZaelous.