My 5th book "50 Tips on JavaScript" is on sale. Go get it from
Illustrated guide to 50 of the most interesting JavaScript topics.

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());
	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. To leave a comment go here.