This works ok. But you should set up some sample files for testing on.
There are some details here on how to use it Rename Scripts
function lpad( val, pad ) {
if (!pad) pad='';
var rtn=val.toString();
return (rtn.length<pad.length) ? (pad+rtn).slice(-pad.length) : val;
}
function OnGetNewName(getNewNameData)
{
var year;
var month;
var day;
var matched = false;
var item = getNewNameData.item;
//DD-MM-YYYY D-M-YY
var reg = new RegExp('([0-1]?\\d)[-.]([0-3]?\\d)[-.]((?:19|20)?[0-9]{1,2})|((?:19|20)?[0-9]{1,2})[-.]([0-3]?\\d)[-.]([0-1]?\\d)');
if(reg.test(item.name))
{
DOpus.OutputString(item.name + " matched 1 DD-MM-YYYY or YYYY-MM-DD");
day = item.name.replace(reg, "$1$6");
month = item.name.replace(reg, "$2$5");
year = item.name.replace(reg, "$3$4");
matched = true;
}
if(!matched)
{
//DDMMYYYY
var reg = new RegExp('([0-1]?\\d)([0-3]?\\d)((?:19|20)[0-9]{2})');
var regexMatch = reg.exec(item.name);
if (regexMatch != null) {
DOpus.OutputString(item.name + " matched 2 DDMMYYYY");
day = regexMatch[1];
month = regexMatch[2];
year = regexMatch[3];
matched = true;
}
}
if(!matched)
{
//YYYYMMDD
var reg = new RegExp('((?:19|20)?[0-9]{2})([0-3]?\\d)([0-1]?\\d)');
var regexMatch = reg.exec(item.name);
if (regexMatch != null) {
DOpus.OutputString(item.name + " matched 3 YYYYMMDD");
day = regexMatch[3];
month = regexMatch[2];
year = regexMatch[1];
matched = true;
}
}
if (matched)
{
getNewNameData = lpad(day, "00") + "-" + lpad(month, "00") + "-" + lpad(year, "0020");
return lpad(day, "00") + "-" + lpad(month, "00") + "-" + lpad(year, "0020");
}
return true;
}
