Rename files to random string?

Is it possible to rename selected files to a random six-digit number? Does this require a script?

function OnGetNewName(getNewNameData)
{
	var name = Math.floor(Math.random()*1000000) + "";
	while (name.length < 6) {
		name = "0" + name;
	}
	return name + getNewNameData.newname_ext_m;
}

It might make sense to have the script check if the random name already exists, and generate another one when it does, but that's left as an exercise for the reader. :slight_smile: Or you could turn on "automatically rename if new filename exists" if you don't mind having (1) etc. appended in those situations.

3 Likes

Thanks Leo, works great.

Regarding a more complex script - it seems you already wrote it! After I posted my question, I found Add a Unique Number while renaming by Leo Davidson (20th Aug 2007) which contains a random function and checks for existing filenames.

1 Like