author: Krasimir Tsonev

Hi there, I'm . Senior front-end engineer with over 13 years of experience. I write, speak and occasionally code stuff. Follow me on Twitter, GitHub, Facebook or LinkedIn

Using Node.js to rename set of images

Today I had to rename a bunch of image files to the same names, but in lower case. Here is how I did it.

Let's say that the folder is called players. The Node.js script looks like that:

var glob = require("glob"),
	path = require("path"),
	fs = require("fs");

glob(__dirname + "/players/**/*.*", function(err, files) {
	var processed = 0;
	files.forEach(function(file) {
		var dir = path.dirname(file);
		var filename = path.basename(file);
		fs.renameSync(file, dir + "/" + filename.toLowerCase());
		processed++;
	});
	console.log(processed + " files processed");
});

And here is the package.json file needed:

{
	"name": "RenameAllToLowerCase",
	"description": "",
	"version": "0.0.1",
	"dependencies": {
		"glob": "*"
	},
	"main": "index.js"
}
If you enjoy this post, share it on Twitter, Facebook or LinkedIn. Or maybe comment below: