Here's a variation that appends a random set of three digits to existing filenames*, to photos, for instance.
- Code: Select all
function makeid(size)
{
var text = "";
var possible = "0123456789";
for( var i=0; i < size; i++ )
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
newName = name + '_' + makeid(3);
If you change this code yourself, note that spaces before and after elements like name, +, '_', are required. Omitting them throws up errors.
NOTE that after you paste the above text into the javascript panel**, the Test button lets you check the code by changing the name of test_file_name.ext You can experiment with the code and re-test. The files themselves don't appear to get saved.
*if you would like to append four digits rather than three, change makeid(3) in the bottom line to makeid(4), ad infinitum..
**save that setup/configuration by choosing File, Save As - to retain it as a .bru Favourite file (otherwise the next time you open the javascript panel, it will be blank).